Code: Select all
$handle = opendir($path) or die "oops!");
echo "<p>Show button was clicked</p>";
echo "<p>Path: $path - Handle: $handle</p>;
while ($file = readdir($handle)
{
// display the JPG image -- this works fine
}
closedir($handle);
Show button was clicked
Path: ./images/ - Handle: Resource id #4
and the images are displayed (at least that part works). I copied this exact code to the block that responds to the Upload button. It failed with:
[Uploadbutton was clicked
Path: ./images/ - Handle: Resource id #4
Warning: readdir(): 4 is not a valid Directory resource in /home/xxx/yyy/store_image3.php on line 166
I then added code to close the directory and open it again:
Code: Select all
$handle = opendir($path) or die "oops!");
echo "<p>Upload button was clicked</p>";
echo "<p>Path: $path - Handle: $handle</p>;
closedir($handle);
$handle = opendir($path) or die "oops!");
echo "<p>Closed and reopened. Path: $path - Handle: $handle</p>;
while ($file = readdir($handle)
{
// Just list the files for now
}
closedir($handle);
Now when I click Upload instead of Show, I see:
Upload button was clicked
Path: ./images/ - Handle: Resource id #4
Closed and reopened. Path: ./images/ - dir_handle: Resource id #5
Warning: readdir(): 5 is not a valid Directory resource in /home/xxx/yyy/store_image3.php on line 170
I note that closedir() had no problem with $handle being a valid directory resource, only readdir().
Does anyone know why readdir() won't work with the Upload button? I'm completely befuddled why identical code with identical directory handles doesn't work identically.
Thanks in advance for any help.
Mike