I decided last night that I needed a PHP driven image gallery and since I didn’t have an internet connection I couldn’t check around for likeminded projects, so I wrote one myself.

It’s a simple and clean PHP script called index.php (clever and unique eh?) You just put it in a folder labeled after the name of the image set. So, for example, if I have a bunch of pictures of france I might call the directory france06. Then, all I would have to do is make two directories inside france06 called thumbs and images and upload the images to the appropriate places.

There is one catch to the whole thing, the thumbnail images and the full sized images have to be named exactly the same thing, extension included. (.jpg, .JPG, .tif, .TIF etc.) I set it up this way to save on code and it just made more sense to me.

The script opens the directory called “thumbs” and lists the files out one by one and puts them into the appropriate place within a list item. So, when you load the page you should see a gallery with all your pictures. You can find a demo of the script here.

A note about styling.

In my edition of the script I simply gave the ul an id of “gallery” (yet another very creative decision on my part…) If you’re using CSS then you’ll just need to make reference to #gallery for styles that change the look of the ul itself and #gallery li to styles that alter the list items within that ul.

Also, please feel free to modify the code as you need. It would be nice to know if you use the script in a project, just for my own personal curiosity. Anyway, hope you enjoy the script.

I guess at some point I should also give a link to the script itself since PHP once rendered isn’t that easy to get ahold of…