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

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

I’m undecided on how to go about posting updates that relate to posts I’ve already made so please bear with me until I work it out. :)

As with last time I wrote an updated post for the Digital Formula PHP File List System, a small project I’m using to ‘practice’ PHP, this post is basically a re-write of what was posted last time but with a few changes that relate to this specific version. The changes between this version (0.4) and the previous version (0.3) are:

  • Option to create missing thumbnails added – can be turned off by setting CREATE_MISSING_THUMBNAILS in constants.php (width/height can be controlled from there too)
  • Tidy of CSS i.e. styles moved from header.php to master.css
  • Option to calculate and output statistics added – can be turned off by setting SHOW_STATISTICS in constants.php
  • Fixed bug where division by zero error during average file size calculations would occur if no files were found
  • Numerous code efficiency changes e.g. moving common code into functions
  • Corrected a number of comments that were leftover from previous versions

This project started because I’m selling a couple of 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 referencing in this article (0.4) has all the changes listed above plus a couple more configuration options that can be found in constants.php.

The list is displayed on screen with the thumbnail shown as a link to the main file, if available. If no thumbnail was found and the option to create missing thumbnails is turned *off* in constants.php another image letting you know that no thumbnail was found is shown instead. If the option to create missing thumbnails is turned *on* an appropriate thumbnail image is created in the thumbs directory specified in constants.php.

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

Usage examples:
“http://digitalformula.net/demos/df_php_file_list_system_0.4/index.php?action=list&id=orbea – Looks for all files that begin with orbea_ in the ./files/ directory relative to the script directory. Looks for thumbnails named tn_orbea_* in the ./files/thumbs/ directory relative to the script directory. Thumbnails exist for all the demo images.

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.4 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 ::

banner ad

Leave a Reply

Powered by Wordpress | Designed by Elegant Themes