Submit FAQs Awards Usage Terms Contact
Categories
Partners
DaniWeb is an exciting community for web developers, Internet marketers, and technology enthusiasts.
Other Sections
Sweet Ads
Compatibility
Bookmark online:

FF1+ IE5+ Opr7+

PHP Photo Album script

Author: Dynamic Drive

Note: Updated Feb 22nd, 06'. Added ability to order images by date (ascending or descending). The default is "by file name", alphabetically.

Description: This is a PHP enhanced Photo Album script that automates the retrieval of all images within a specific directory to show, with links to cycle through each batch of images. It's based on the original Photo Album script, though uses PHP to automatically populate the script with all images within a directory. As you upload or modify images within the directory, the script automatically adapts! Some attributes of this script are:

  • Uses an external PHP file to retrieve all images within a directory to show on the fly.
  • Customize the album's dimensions as desired, such as 3 by 2 images, 4 by 5 images etc.
  • Ability to sort the display order of the images by file date (ascending or descending). The default is "by file name" (alphabetically). New
  • The script automatically builds navigational links to allow the viewer to cycle between "batches" of images.
  • Each batch of images are only downloaded when they are viewed.
  • Each image is hyperlinked to itself or to a larger version of the image, and the link can optionally be set to open in a popup window. (note)
  • CSS based styling for easy customization and very lightweight code.

This script requires that your server is capable of running a PHP file (to retrieve the image file names of a specific directory), though the pages themselves that will display the photo album can be any regular HTML page.

Demo (links are set to open in a popup window):

Credits: Images for illustrative purposes only, obtained from Jaguar.com


Directions Developer's View

Step 1: Download "getpics.php" (right click, and select "Save As"), and be sure to remove the .txt extension at the end upon downloading! Then, upload this file to the SAME directory on your server containing all the images you wish the Photo Album script to display, for example, http://www.mysite.com/gallery/. This PHP script will get the file names of all images within this directory, and return it back to the Photo Album script to use to display.

Step 2: Add the following CSS to the <head> section of your page:

Select All

Step 3: Add the below HTML code to the <BODY> section of your page where you wish the photo album to appear:

Select All

You're almost there- now be sure that the reference to the PHP file inside the code of Step 3 is correct:

<script src="http://www.mysite.com/gallery/getpics.php" type="text/javascript"></script>

where "http://www.mysite.com/gallery/getpics.php" correctly refers to the location of the PHP script on your server, and "gallery" is in fact the directory containing all the images you wish to be shown. Be sure the variable "imagepath" is set up in a similar fashion as well.

All that's left now is to configure a few more options within the code of Step 3 per the comments, such as whether the links should open in a popup window, the text to display underneath each image (ie Photo 1, Photo 2 etc) etc.

Enjoy!

Notes

By default, each image within the gallery simply links to itself. However, if you wish them to link to larger versions of themselves, you can specify an alternate directory in which the larger images are located. The file names of these large images should mirror those of the original. To do this, change the variable of Step 3:

var targetlinkdir=""

to something like:

var targetlinkdir="http://www.mysite.com/largegallery/"

This will cause the script to use the directory above instead when loading the image associated with the thumbnail. Obviously you'll need to create an enlarged version of each image, upload them to this directory and maintaining the same file names as the original in order for this to work.