The journal of David Brooks, designer, developer and photographer.

An Automatic Image Gallery Using PHP

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…

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.

Recent Articles

Latest Comments

Northward Compass

Colophon

© 2005 - 2010 David Brooks, all rights reserved.