I am trying to process and display two images. The processing and the moving of the two images to a folder works. Now I am trying to display both images in the same web page that processed them. I just need their file names and directories.
I think I have narrowed down the problem so I have removed a lot of code to make it simpler. It looks to me that the array in $ndfilenm disappears as it leaves the first foreach block.
How do I resolve this; Is there a way to access that array later in the second foreach block to display the image? Thanks.
<?php
foreach ($_FILES['image']['name'] as $number => $file) {
// A bunch of php here.
$ndfilenm = UPLOAD_DIR . $filenm;
var_dump($ndfilenm); // dumps out two image directory and names, "great".
}
var_dump($ndfilenm); // dumps out only the last image directory and name, "not both".
?>
Some html here.
<?php
// Warning: Invalid argument supplied for foreach()
if (isset($ndfilenm)) {
foreach ($ndfilenm as $item) {
echo "<img src= '$item' />";
}
}
?>
It did not work the first time because I put brackets next to all $ndfilenm variables. I guess brackets are only used when putting info into a variable as apposed to accessing info from.
I am moving the two image files (an array in $udfilenm) to a folder and changing the two tmp names to permanent names with their directory addresses appended to each. Then I am saving this array in $ndfilenm. (nd) stands for new directory.
I tried this:
$ndfilenm[] = UPLOAD_DIR . $filenm;
but I got some errors. $ndfilenm goes through an image reduction process next and then that’s the end of the first foreach block.