Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Problem: What's an Illegal offset type?

NeakNeak Posts: 87Member
[code][red]Warning: Illegal offset type in /home/exirptco/public_html/gallery/mod.php on line 135

Warning: implode(): Bad arguments. in /home/exirptco/public_html/gallery/mod.php on line 135

Warning: Illegal offset type in /home/exirptco/public_html/gallery/mod.php on line 135

Warning: Illegal offset type in /home/exirptco/public_html/gallery/mod.php on line 135

Warning: implode(): Bad arguments. in /home/exirptco/public_html/gallery/mod.php on line 135

Warning: Illegal offset type in /home/exirptco/public_html/gallery/mod.php on line 135[/red][/code]
There's my beautiful error.

I have no idea what the problem is, and I'm hoping it's more common a problem than it seems, and that someone will know how to fix it. For reference, here's the error line (135) and the surrounding 2 blocks of code.

[code] $NewStuff[0] = $_POST['title'];
$NewStuff[1] = $_SESSION['handle'];
$NewStuff[2] = $_POST['date'];
$NewStuff[3] = $_POST['medium'];
$NewStuff[4] = $_POST['comment'];

$ImagePath = $_POST['path'];

array_unshift($exploded, $NewStuff);

//---IMPLOSION---------------------------------------------------------------------------------
$Fopened = fopen($Fooage, 'w'); // Fopened file.
$Freaded = fread($Fopened, filesize($Fooage)); // Fread File.

// implode the parts, then implode them all together
foreach ($exploded as $index) // Go through each part of $exploded
{
[red]$implodedFirst[$index] = implode("
", $exploded[$index]); // Implodes each part[/red]
// depending on single new line.
}
$imploded = implode("

", $implodedFirst); // Implode by 2x new line...

fputs($Fopened, $imploded);
fclose($Fopened);
//---------------------------------------------------------------------------------------------

// Image Uplosion
ImgUpload($NewStuff[0], $NewStuff[1], $_FILES); [/code]

Comments

  • netgertnetgert Posts: 331Member
    : [code][red]Warning: Illegal offset type in /home/exirptco/public_html/gallery/mod.php on line 135
    :
    : Warning: implode(): Bad arguments. in /home/exirptco/public_html/gallery/mod.php on line 135
    :
    : Warning: Illegal offset type in /home/exirptco/public_html/gallery/mod.php on line 135
    :
    : Warning: Illegal offset type in /home/exirptco/public_html/gallery/mod.php on line 135
    :
    : Warning: implode(): Bad arguments. in /home/exirptco/public_html/gallery/mod.php on line 135
    :
    : Warning: Illegal offset type in /home/exirptco/public_html/gallery/mod.php on line 135[/red][/code]
    : There's my beautiful error.
    :
    : I have no idea what the problem is, and I'm hoping it's more common a problem than it seems, and that someone will know how to fix it. For reference, here's the error line (135) and the surrounding 2 blocks of code.
    :
    : [code] $NewStuff[0] = $_POST['title'];
    : $NewStuff[1] = $_SESSION['handle'];
    : $NewStuff[2] = $_POST['date'];
    : $NewStuff[3] = $_POST['medium'];
    : $NewStuff[4] = $_POST['comment'];
    :
    : $ImagePath = $_POST['path'];
    :
    : array_unshift($exploded, $NewStuff);
    :
    : //---IMPLOSION---------------------------------------------------------------------------------
    : $Fopened = fopen($Fooage, 'w'); // Fopened file.
    : $Freaded = fread($Fopened, filesize($Fooage)); // Fread File.
    :
    : // implode the parts, then implode them all together
    : foreach ($exploded as $index) // Go through each part of $exploded
    : {
    : [red]$implodedFirst[$index] = implode("
    ", [blue]$exploded[$index][/blue]); // Implodes each part[/red]
    : // depending on single new line.
    : }
    : $imploded = implode("

    ", $implodedFirst); // Implode by 2x new line...
    :
    : fputs($Fopened, $imploded);
    : fclose($Fopened);
    : //---------------------------------------------------------------------------------------------
    :
    : // Image Uplosion
    : ImgUpload($NewStuff[0], $NewStuff[1], $_FILES); [/code]
    :
    $index is already an element from the array of $exploded, so use [blue]$index[/blue] insead of that part
    Also, find another solution for the [green]$implodedFirst[$index][/green] part, as $index probably isnt good for index, being a value of an array rather than index/key
    You've misunderstood the [b]foreach[/b] statement
    the code might work when the foreach line would read (not tested):
    foreach ($exploded => $index) // Go through each part
    [hr][red][italic][b]N[/b][/red][blue]et[/blue][red][b]G[/b][/red][blue]ert[/italic][/blue][hr]

  • NeakNeak Posts: 87Member
    [b][red]This message was edited by Neak at 2004-8-6 10:27:48[/red][/b][hr]
    [b][red]This message was edited by Neak at 2004-8-6 10:23:28[/red][/b][hr]
    : $index is already an element from the array of $exploded, so use [blue]$index[/blue] insead of that part
    : Also, find another solution for the [green]$implodedFirst[$index][/green] part, as $index probably isnt good for index, being a value of an array rather than index/key
    : You've misunderstood the [b]foreach[/b] statement
    : the code might work when the foreach line would read (not tested):
    : foreach ($exploded => $index) // Go through each part
    : [hr][red][italic][b]N[/b][/red][blue]et[/blue][red][b]G[/b][/red][blue]ert[/italic][/blue][hr]
    :
    Bleh. Well, I thought I understood the foreach loop, because the code was copied and pasted from a different section of my site, which I wrote earlier (this code was the gallery section, copied from the news section.)
    The only difference was the variable names. And, the news section code works fine. Here are both scripts for comparison.
    Gallery Section (doesn't work):
    [code] $NewStuff[0] = $_POST['title'];
    $NewStuff[1] = $_SESSION['handle'];
    $NewStuff[2] = $_POST['date'];
    $NewStuff[3] = $_POST['medium'];
    $NewStuff[4] = $_POST['comment'];

    $ImagePath = $_POST['path'];

    array_unshift($exploded, $NewStuff);

    //---IMPLOSION---------------------------------------------------------------------------------
    $Fopened = fopen($Fooage, 'w'); // Fopened file.
    $Freaded = fread($Fopened, filesize($Fooage)); // Fread File.

    // implode the parts, then implode them all together
    foreach ($exploded as $index) // Go through each part of $exploded
    {
    $implodedFirst[$index] = implode("
    ", $exploded[$index]); // Implodes each part
    // depending on single new line.
    }
    $imploded = implode("

    ", $implodedFirst); // Implode by 2x new line...

    fputs($Fopened, $imploded);
    fclose($Fopened);
    //---------------------------------------------------------------------------------------------

    // Image Uplosion
    ImgUpload($NewStuff[0], $NewStuff[1], $_FILES); [/code]
    News Section (does work):
    [code] $NewStuff[0] = $_POST['title'];
    $NewStuff[1] = $_SESSION['handle'];
    $NewStuff[2] = $_POST['date'];
    $NewStuff[3] = $_POST['content'];

    array_unshift($exploded, $NewStuff);

    //---IMPLOSION---------------------------------------------------------------------------------
    $Fopened = fopen($Fooage, 'w'); // Fopened file.
    $Freaded = fread($Fopened, filesize($Fooage)); // Fread File.

    // implode the parts, then implode them all together
    foreach ($exploded as $index) // Go through each part of $exploded
    {
    $implodedFirst[$index] = implode("
    ", $exploded[$index]); // Implodes each part
    // depending on single new line.
    }
    $imploded = implode("

    ", $implodedFirst); // Implode by 2x new line...

    fputs($Fopened, $imploded);
    fclose($Fopened);
    //---------------------------------------------------------------------------------------------[/code]

    [red]Does anyone know why one code would work when it's practically identical to the code that doesn't?[/red]


  • NeakNeak Posts: 87Member
    : The only difference was the variable names. And, the news section code works fine. Here are both scripts for comparison.
    : Gallery Section (doesn't work):
    : [code] $NewStuff[0] = $_POST['title'];
    : $NewStuff[1] = $_SESSION['handle'];
    : $NewStuff[2] = $_POST['date'];
    : $NewStuff[3] = $_POST['medium'];
    : $NewStuff[4] = $_POST['comment'];
    :
    : $ImagePath = $_POST['path'];
    :
    : array_unshift($exploded, $NewStuff);
    :
    : //---IMPLOSION---------------------------------------------------------------------------------
    : $Fopened = fopen($Fooage, 'w'); // Fopened file.
    : $Freaded = fread($Fopened, filesize($Fooage)); // Fread File.
    :
    : // implode the parts, then implode them all together
    : foreach ($exploded as $index) // Go through each part of $exploded
    : {
    : $implodedFirst[$index] = implode("
    ", $exploded[$index]); // Implodes each part
    : // depending on single new line.
    : }
    : $imploded = implode("

    ", $implodedFirst); // Implode by 2x new line...
    :
    : fputs($Fopened, $imploded);
    : fclose($Fopened);
    : //---------------------------------------------------------------------------------------------
    :
    : // Image Uplosion
    : ImgUpload($NewStuff[0], $NewStuff[1], $_FILES); [/code]
    : News Section (does work):
    : [code] $NewStuff[0] = $_POST['title'];
    : $NewStuff[1] = $_SESSION['handle'];
    : $NewStuff[2] = $_POST['date'];
    : $NewStuff[3] = $_POST['content'];
    :
    : array_unshift($exploded, $NewStuff);
    :
    : //---IMPLOSION---------------------------------------------------------------------------------
    : $Fopened = fopen($Fooage, 'w'); // Fopened file.
    : $Freaded = fread($Fopened, filesize($Fooage)); // Fread File.
    :
    : // implode the parts, then implode them all together
    : foreach ($exploded as $index) // Go through each part of $exploded
    : {
    : $implodedFirst[$index] = implode("
    ", $exploded[$index]); // Implodes each part
    : // depending on single new line.
    : }
    : $imploded = implode("

    ", $implodedFirst); // Implode by 2x new line...
    :
    : fputs($Fopened, $imploded);
    : fclose($Fopened);
    : //---------------------------------------------------------------------------------------------[/code]
    :
    : [red]Does anyone know why one code would work when it's practically identical to the code that doesn't?[/red]

    Anybody?
  • NeakNeak Posts: 87Member
    Wow. Well, I've gone through two of my files: the file for modifying news content on my website and the file for modifying image gallery content.

    I made the news section of the site first, as it's the openning page. It works.

    Then, I copied and pasted the code and changed parts for the gallery section. It should work, I only changed a few things, mostly just adding an image uploading function and random thumbnail generator.

    I use Vim text editor, so I can open two files in one window to compare them. I've gone through the loops, line by line, comparing the two files. I've replaced code from the gallery section with code from the news section to try and find where the error is coming from. To no avail. No matter what I do, the same error occurs:[code]Warning: Illegal offset type in /home/exirptco/public_html/gallery/mod.php on line 134

    Warning: implode(): Bad arguments. in /home/exirptco/public_html/gallery/mod.php on line 134

    Warning: Illegal offset type in /home/exirptco/public_html/gallery/mod.php on line 134

    Warning: Illegal offset type in /home/exirptco/public_html/gallery/mod.php on line 134

    Warning: implode(): Bad arguments. in /home/exirptco/public_html/gallery/mod.php on line 134

    Warning: Illegal offset type in /home/exirptco/public_html/gallery/mod.php on line 134[/code]

    I've been working on this for so long and I truly can not find a solution. I'm thinking that maybe someone here, if anyone has the time, could look at the files and tell me if they know the problem. Here are links to the two files in a .txt format.

    http://www.exirpt.com/help/news_mod.txt News Script
    http://www.exirpt.com/help/gallery_mod.txt Gallery Script

    If anyone could help me it would be greatly appreciated.
Sign In or Register to comment.