← Travel Tip: Airport Security User Error: No the computer does not know the future. →
Code Snippet: Get a random image from a directory.
09/08/2009
This can be useful for banner ads.
function getRandomImage( ) {
$path = “”; // Replace with your path
$img_list = array();
$dir = opendir( $path );
// Get all the files in the directory
while( $img = readdir($dir) )
{
if( $img != “.” && $img != “..”)
{
$img_list[] = $img;
}
}
closedir($dir);
// Randomly select a file from the list
$rand_img = rand(0, count($img_list)-1 );
$rand_img = $img_list[$rand_img];
return $rand_img;
}
This entry was posted in Uncategorized. Bookmark the permalink.
← Travel Tip: Airport Security User Error: No the computer does not know the future. →
Leave a Reply
You must be logged in to post a comment.







