Aleš Gabrovec - tagged with code http://www.gabrovec.com/feed My lifestream en-us http://blogs.law.harvard.edu/tech/rss Sweetcron ales.gabrovec@gmail.com Get Lightbox to Read Images From a Directory http://www.gabrovec.com/items/view/170/get-lightbox-to-read-images-from-a-directory

I recently came accross a project where I wanted to have the ability to display all the images in a directory dynamically using Lightbox. With a few lines of php, I was able to generate the necessary HTML to get the Lightbox to show the images.

Here's the PHP fucntion:

function returnimages($dirname=".") {
$pattern="(.jpg$)|(.png$)|(.jpeg$)|(.gif$)"; //possible filetypes
$curimage=0;
if($handle = opendir($dirname)) {
while(false !== ($file = readdir($handle))){
if(eregi($pattern, $file)){
echo '<li><a href="'.$file.'"><img src="'.$file.'" alt="" width="120" height="80" /></a></li>';
$curimage++;
}
}
closedir($handle);
}
}
returnimages();

 

The code simply looks in the directory and outputs specific HTML appropriate for lightbox.

View an example of the Lightbox gallery reading images from a directory. Have a look at the source code to see how it all works.

Download a ZIP containing everything you need.

 

]]>
Wed, 04 Feb 2009 02:52:30 -0800 http://www.gabrovec.com/items/view/170/get-lightbox-to-read-images-from-a-directory