Here is one I use.
PHP Code:
<?php
//Edit this line to the url of your image folder to randomize
//Must be a relative URL in your server, do not put in a forward
//or trailing slash for it to work.
$url='photo/pics';
//Stop editing, that is all. Call the image with <img src=url/filename.php> That's all, enjoy. :D
$files=array();
if ($handle=opendir("$url")) {
while(false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
if(substr($file,-3)=='gif' || substr($file,-3)=='jpg' || substr($file,-3)=='png' || substr($file,-3)=='bmp') $files[count($files)] = $file;
}
}
}
closedir($handle);
$random=rand(0,count($files)-1);
if(substr($files[$random],-3)=='gif') header("Content-type: image/gif");
elseif(substr($files[$random],-3)=='jpg') header("Content-type: image/jpeg");
elseif(substr($files[$random],-3)=='png') header("Content-type: image/png");
elseif(substr($files[$random],-3)=='bmp') header("Content-type: image/bmp");
readfile("$url/$files[$random]");
?>