|
<?php $dir = '.'; // '.' means: the current directory this script resides $array = array(); // nothing mt_srand((double)microtime()*1000000); $handle = opendir($dir); while (false !== ($file = readdir($handle))) { $extention = strtolower(substr(strrchr($file,"."),1)); if($extention == 'jpg' || $extention == 'jpeg' || $extention == 'jpe' || $extention == 'gif' || $extention == 'png' || $extention == 'bmp'){ $array[] = $file; } } $count = count($array); $num = mt_rand(0, ($count-1)); if($count > 0){ $size = getimagesize($array[$num]); $stream = fopen($dir.'/'.$array[$num], "rb"); if($size && $stream){ header("Content-type: ".$size['mime']);fpassthru($stream); //fpassthru closes the stream by itself exit(); } }else{ echo 'no images'; } ?> |