Chris Rasmussen · Photographer · Infrastructure Guy · Code Dabbler · Traveller

PHP script to show files in directory with a bit of style – v0.3

This is a re-write of a post I made I recently about a PHP file list system I’ve been hacking about with. The original article, entitled PHP script to show images in directory with a bit of style, can be found by clicking the link you just went past. I’d *highly* recommend using the scripts and downloads referenced by this article, though. Please note that the content below is almost identical the original article but with a couple of minor changes relating to what the script does.

I’m selling a couple things on ebay at the moment. Unfortunately I don’t have a lot of choice because there isn’t really an alternative here in Australia that can compete. In NZ I would be using Trade Me, whose interface etc I really like, but here, it’s ebay. Anyway, I sold 1 item recently and was shocked to find that I got charged to LIST the item, got charged when the item SOLD, got charged when the buyer PAID me and then, to add insult to injury, got charged again when I took MY own money from MY PayPal account! You gotta be kidding me …

I’ve got a few more things to sell on ebay and rather than be allowed a single image for free and then pay AUD$0.25 for each subsequent image (Trade Me is the same but I think NZD$0.10 per additional photo is easier to stomach) I decided to throw together a quick PHP script that I’ve been meaning to write for some time. It simply takes a list of the image files (JPG, JPEG, GIF and PNG) in a specified directory and builds a page to display them on. The version I’m putting in this article has a whole load of error checking although it’s purely for my use so please understand if I don’t check for every single possible outcome or error. The original version of this script built the list of files and checked in a subdirectory called ‘thumbs’ to see if there is a file beginning with the prefix ‘tn_’ that matched the name of each file found in the main directory – this version does the same thing but is FAR more configurable.

The architecture, if I can call it that, is completely different too. I’m using this mini project as a way of practicing some PHP so I’ve moved a lot of the re-used code into classes and includes. The configuration options in constants.php and error_codes.php allow you to change the way a lot of the script works, from where the files live, the name of the site’s logo image, the number of items displayed per row of images to the customisation of error codes.

The list is displayed on screen with the thumbnail shown as a link to the main file, if available. If no thumbnail was found another image letting you know that no thumbnail was found is shown instead. The links show each image as a jQuery/Lightbox ‘popup’ – not a new thing but I’ve always quite liked Lightbox. The original version of this script used index.php to show the images too – this functionality has been removed.

Hopefully someone finds this script useful. Oh, and the script produces W3C-valid XHTML 1.0 markup, too … ;)

Usage examples:
“http://digitalformula.net/demos/df_php_file_list_system_0.3/index.php?action=list&id=phone – Looks for all files that begin with phone_ in the ./files/ directory relative to the script directory. Looks for thumbnails named tn_phone_* in the ./files/thumbs/ directory relative to the script directory. If a thumbnail doesn’t exist for a particular file, the no_thumbnail.jpg image will be shown instead.

Note: The code that used to be shown in the old article was a fully functional but slightly older version of the current version of this script. If you would like to download the latest version of the Digital Formula PHP File List System v0.3 please go to the Digital Formula Downloads page and grab it from there instead. Thanks!

:: Code Removed 2009/08/28; Please use the Digital Formula Downloads page instead ::

Leave a Reply

Powered by Wordpress | Designed by Elegant Themes