Code Snippet: Photo Randomiser

This was something I quickly threw together to randomise a folder of photos.
Basically you put all your photos in one folder, it then randomly copies them to an output folder with a new file name.
This was used for randomising photos for a photo DVD at a party.

Its fine for basic things. If you plan on using it for a website or something I would suggest tweaking the code a bit.
Also note that it was only written to handle .jpg files. It wouldn’t be too hard to modify it though.

Feel free to use the code as you wish.


// Shuffle the array

echo “

$file_count = 1;

// Loop through the file array list
foreach($file_list as $value) {

// Copy the file to the output dir with its new name. I use a number for the output file to keep the files in their shuffled order.
copy($in_dir . $value, $out_dir . $file_count . “.jpg”);



echo “


Leave a Reply