PHP Programming

Sorting your photo collection by date the PHP way

Ever wanted to sort your photo collection in the order by date taken? Can’t find the right program that will do it for you? I decided that I had a large enough collection myself to warrant organizing, but I could not find a program that can organize it the way I want it. I have always wanted the photos to be sorted by the date taken and grouped by the year, so I decided to create a short script for myself.

Before I get into the code, you’ll want to check that your PHP settings will allow the script to run by making sure the needed DLLs are enabled. The script uses the exif extension, but will also require mbstring enabled:

Also note that mbstring must be loaded before the exif DLL. Visit for more information.

The Code

You must forgive me for the lackluster comments as I didn’t think I’d be sharing this code. The code isn’t too hard to read, and in my opinion is straight forward for the average programmer. For those that are beginners just remember to set the $dir and $target_dir variables for this script to work.

To give an idea what this script will do, if I have three files I want to sort:

The script will determine the timestamps of each file and place them in folders belonging to its years, while prefixing the filenames with the timestamps:

It’s not the greatest script but I’m happy with my results.

Leave a Reply

Your email address will not be published. Required fields are marked *