This message was edited by Neak at 2004-8-6 10:27:48
This message was edited by Neak at 2004-8-6 10:23:28
: $index is already an element from the array of $exploded, so use
$index insead of that part
: Also, find another solution for the
$implodedFirst[$index] part, as $index probably isnt good for index, being a value of an array rather than index/key
: You've misunderstood the
foreach statement
: the code might work when the foreach line would read (not tested):
: foreach ($exploded => $index) // Go through each part
:
NetGert[/italic]
:
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):
$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("\r\n", $exploded[$index]); // Implodes each part
// depending on single new line.
}
$imploded = implode("\r\n\r\n", $implodedFirst); // Implode by 2x new line...
fputs($Fopened, $imploded);
fclose($Fopened);
//---------------------------------------------------------------------------------------------
// Image Uplosion
ImgUpload($NewStuff[0], $NewStuff[1], $_FILES);
News Section (does work):
$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("\r\n", $exploded[$index]); // Implodes each part
// depending on single new line.
}
$imploded = implode("\r\n\r\n", $implodedFirst); // Implode by 2x new line...
fputs($Fopened, $imploded);
fclose($Fopened);
//---------------------------------------------------------------------------------------------
Does anyone know why one code would work when it's practically identical to the code that doesn't?