I'm trying to create a system where a user will select an image, click "Add" and the page will send the image to itself. The page will then add the image to an array, echo out the same form as before, and start a list of images in the array below the form.
But, the issue I'm having is that when ever I click "Add" the page refreshes and whatever was in the array was replaced by whatever was in my file box.
This shouldn't be happening because I'm incrementing the key each time I write to the array.
Plus, I have an in_array() check to make sure duplicate images won't get stored, and it looks right past that.
I've included most of the code from the problem section of my script. (I striped most of the HTML out of it to keep it simple) The session that you see here is set up earlier in the script and contains data. Any insight would be greatly appreciated. Thanks
$imgList = Array(); // Create the array that will store the list of images to upload
$addImg = $_POST['addImg']; // Incomming IMG
if(in_array("$addImg",$imgList)){ // Check if incomming IMG image is already in array
$report = "The image you selected has already been added to the list of images to upload. Please try again.";
}else{
$_SESSION['incKey']++; // Increment the KEY
$incKey = $_SESSION['incKey']; // and dump it into a string
$imgList["$incKey"] = "$addImg"; // Add the IMG to the array with the incremented key
}
echo <<<HTML
INSTRUCTIONS: Use the file box below to add images to the upload list.
When you have selected all the images you want to upload,
click the upload button at the bottom of the page.
Please note that the first file you select will be the first
image to appear when this portfolio entry is viewed.
$report
<form action="$php_self?mod=$mod&sec=$sec&key=3" method="POST">
<input type='file' name='addImg' style='height:18px;width:400px;padding-left:5px;'>
<input type='submit' value='Add' style='width:50px;height:18px;'>
</form>
<form action="$php_self?mod=$mod&sec=$sec&key=4" method="POST">
HTML;
foreach($imgList as $img){ // List each file in the array
echo "<tr><td>$img</td></tr>";
echo "<input type='hidden' name='img[]' value='$img'>";
}
print_r($imgList); // Dump the array because it sucks and won't work
echo "</form></table>";