Forum Moderators: coopster
the script works as if the page is an image such as <img src="/images/thumbnail.php?Image003.jpg">
I would like to loop through all of the files in a directory using a loop and a single command like <img src="/images/thumbnail.php?<?php echo $filename?>"> where $filename picks the next file in the folder.
I know that PHP is able to read directories and I would be able to do this if the filenames were in a database. Is anyone able to connect the dots for me and let me know how to get this done. thanks.
<?
$mydir = "/path/to/dir/";
$d = dir($mydir);
while($entry = $d->read()) {
if ($entry!= "." && $entry!= "..") {
echo "<br><img src=\"/images/thumbnail.php?",$entry,"\">";
}
}
$d->close();
?>
I didn't test this but it should work. You just set the $mydir var and it should spit all your thumbnails out to the screen. I use this little filename reader a lot, it comes in quite handy. ;)
[edited by: jatar_k at 7:03 pm (utc) on April 19, 2004]
$glob = glob("/path/to/dir/{*.gif,*.jpg}", GLOB_BRACE);
natcasesort($glob);
foreach ($glob as $filename) {
echo "<br><img src=\"/images/thumbnail.php?",$filename,"\">";
}
...however, after some extensive testing, I've learned a few things about our friend, glob. {*.GIF,*.Gif,*.giF} will not match any files with a .gifextension!