Skip to content

Instantly share code, notes, and snippets.

@raoul2000
Created February 21, 2014 10:57
Show Gist options
  • Save raoul2000/9132434 to your computer and use it in GitHub Desktop.
Save raoul2000/9132434 to your computer and use it in GitHub Desktop.
pick a random image from a folder
<?php
//This will get an array of all the gif, jpg and png images in a folder
$img_array = glob("/path/to/images/*.{gif,jpg,png}",GLOB_BRACE);
//Pick a random image from the array
$img = array_rand($img_array);
//Display the image on the page
echo '<img alt="'.$img_array[$img].'" src="'.$img_array[$img].'" />';
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment