Created
February 21, 2014 10:57
-
-
Save raoul2000/9132434 to your computer and use it in GitHub Desktop.
pick a random image from a folder
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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