Mega Code Archive

 
Categories / Php / File Directory
 

Random Image Display

<?php // Store all your images that you want to display in the same folder you specified // above. DO NOT store anything you do not want to display such as files. // This script reads the entire folder you specify and displays the contents at random // If you want to retain the size of the images, add a width to the last line $Image_Path = "/path/to/site/root"; // Root Path - no slash on end $Image_Folder = "Images"; // Directory name of the folder storing your images srand((double) microtime() * 10000000); $imgdirpath = opendir("$Image_Path/$Image_Folder"); while (false !== ($imgfile = readdir($imgdirpath))) { if ($imgfile != "." && $imgfile != "..") { $imgpath = "$Image_Path/$Image_Folder/$imgfile"; $imageimg[$imgfile] = basename($imgpath); } } closedir($imgdirpath); shuffle($imageimg); list( ,$img_value) =each($imageimg); echo "<img src=\"$Image_Folder/$img_value\">\n"; ?>