Very simple PHP ‘gallery’ script
Published November 1st, 2007Somebody asked for a very simple script that would scan a directory (and its subdirectories) for all images, and then present them all as a list of thumbnails. So I had a quick go and came up with this (zip file). Just place the two PHP files in the directory you want to scan, open that URL in your browser and presto! a great big list of all your images.
Yes it’s very basic, but that was the point. No, you can’t add captions, or change the order, or have a whizzy rotating slideshow with cute sound effects.
However you can alter the output size of the thumbnails (using the $max_width and $max_height values) and the number of thumbnails in each row of the list table (using the $images_per_row value). The markup is very simple too so you should be able to alter the layout quite easily if you feel the need.
What’s it good for? Well if you just want to dump images into a folder and see them in a list, then it’s ideal.
Gigs on September 8, 2008
Giving this a try, thanks for it!
Gigs on September 9, 2008
$format = strtolower($matches[ 1 ]);
This works better because you were breaking on *.JPG capitals in get_image.php $format case statement.
Éric on December 23, 2008
I added:
sort($directories[$directory]);
just after:
$directory_reader->close();
as I’m a kinda freak-control
Thanks for it, it’s just what I was looking for.
eric on April 1, 2009
Great!
thanks.
évolétíqué on April 16, 2009
Thank you for sharing this, it is indeed nice and simple and almost perfect for my requrements but can someone tell me how to allow for images with a “‘” in their names. At present there is no thumbnail displayed for images with, example, “there’s your logo.png”?
Roger on May 14, 2009
Perfect, thank you!
Kurakun on June 30, 2009
Hello there stickman.
i got a problem at the script.
I uploaded it to my server, but when i browse my gallery, the image’s are broken, but then when i click em, they show up as they should.. and when i load the index file, they show up fine o__x.. i did a <?php include.. could that be the reason why they break?
Omer on July 11, 2009
Took me a long time to find a script as simple as this, it was exactly what I was looking for!
thanks a bunch.
Catfish on September 9, 2009
+1 for comment number 3 with the sorting code.
This is a cool gallery script that couldn’t get much simpler.
Nošené kalhotky on December 10, 2009
Thanks for sharing this script. Never new about it. Could I share it on other websites?
Jesse on May 22, 2010
Love it, awesome! But would love it even more if it was out putted as an unordered list and generated square thumbnails… Wink…
Thanks for sharing