Home > Programming > Show thumbnails from a directory on your web server.

Show thumbnails from a directory on your web server.

December 20th, 2009 Jimmy Leave a comment Go to comments

The following PHP code will display a set of jpeg files from a folder on your webserver. This code can be used to generate a list of thumbnails provided that the thumbnails are already resized. This code simply outputs the images “img” html tag with the “src” already in place. I would recommend putting this inside a “<div>” tag so that you can control the height and width of the images together. Creating CSS for your image can also control the actual size of the image, or you could just add a width or height to the img tag for auto-scaling.

&lt;?
$directory = opendir(&quot;/home/jimbob/www/htdocs/mypics&quot;);
while ($file = readdir($directory)) {
        if (preg_match(&quot;/\.jpg/&quot;,$file)) {
           echo &quot;&lt;img src=\&quot;drawthumb.php?http://somewebsite.com/mypics/$file\&quot; border=1&gt;&quot;;
           echo &quot;&amp;nbsp;&quot;;
        }
}
closedir($directory);
?&gt;
Categories: Programming Tags:
Digg: DIGG ME
  1. No comments yet.
  1. No trackbacks yet.