Forum Moderators: coopster

Message Too Old, No Replies

saving dynamic thumbs to server

         

generic

3:13 am on Feb 15, 2010 (gmt 0)

10+ Year Member



I have a bit of code that grabs image files from a given directory, thumbnails them and displays them all in a jquery lightbox type gallery. Right now it just resizes on every reload which is a big resource sucker. Can anyone help me modify this code to:

- allow the code to save each thumbnail to a '/thumbs' directory on the first load
- check for the related thumbnail each time the image loads, or create a new thumb if one doesn't exist

Thanks.


$path = "images/gallery/";
$dir_handle = @opendir($path) or die("Unable to open folder");

while (false !== ($file = readdir($dir_handle))) {

if($file == "thumbnail.php")
continue;
if($file == ".")
continue;
if($file == "..")
continue;

$caption = "2009 Photos";

echo '<li><a href="images/gallery/'.$file.'" rel="lightbox-2009" title="'.$caption.'"><img src="images/gallery/thumbnail.php?im='.$file.'" alt="'.$file.'" /></a></li>';

}
closedir($dir_handle);

coopster

1:43 pm on Feb 26, 2010 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



The PHP function, file_exists() may be what you need here. Build the file path and file name and pass it it to the file_exists function. Or better yet, use is_file [php.net].