Very simple PHP ‘gallery’ script

Published November 1st, 2007

Somebody 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.

Get a Trackback link


  1. Gigs on September 8, 2008

    Giving this a try, thanks for it!

  2. 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.

  3. Éric on December 23, 2008

    I added:
    just after:
    as I’m a kinda freak-control :-)

    Thanks for it, it’s just what I was looking for.

  4. eric on April 1, 2009


  5. é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”?

  6. Roger on May 14, 2009

    Perfect, thank you!

  7. 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?

  8. 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.

  9. 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.

  10. Nošené kalhotky on December 10, 2009

    Thanks for sharing this script. Never new about it. Could I share it on other websites?

  11. 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

  12. Simon on July 16, 2010

    I ran the script and get this error

    “PHP Warning: imagecopyresampled(): supplied argument is not a valid Image resource in /home/tide/public_html/photo/get_image.php on line 61″

    Thanks Simon

  13. Paolo Modena on September 18, 2010

    I got a problem at the script.
    I uploaded it to my server, but when i browse my gallery, some images are broken, but then when I click over, they show up in right way. why they break?
    Best regards and thank you for the script.

  14. Phil on November 5, 2010

    Hello all!

    I must agree that indeed this is by far one of the easiest customizeable scripts I’ve come accross in a long time! I’ve completely gotten rid of the table layout, as well as integrated a fully automatically functional shadowbox :D

    However I do have a slight problem. I can’t seem to figure out how to change the .php script so that it doesn’t pick up all images located in the same folder (and subdirectories). It’d be great if you could state a directory and it would only grab images from there (including the chosen folders subdirectories). Since I’ve integrated the shadowbox it grabs images from there as well, which is not really the point ;)

    Id be more than glad to figure where and how the script grabs the images…



  15. hue on December 2, 2010

    Simple and works great, Thank you!

  16. Michael on March 30, 2011

    I just have to say that this is exACTly what I was looking for tonight. Quick, easy, no frills… just exactly what it sets out to do, and simple enough that I can customize it later down the road when I have more time.

    Thanks for sharing this!!!

Leave a comment

Comment Policy: First time comments are moderated. Please be patient.