<?
function GetFileList($dirname, $extension = FALSE, $reverse = FALSE)
{
if(!$extension) //EXTENSIONS OF FILE YOU WANNA SEE IN THE ARRAY
$extension = array("jpg", "png", "jpeg", "gif");
$files = array();
$dir = opendir($dirname);
while(false !== ($file = readdir($dir)))
{
//GET THE FILES ACCORDING TO THE EXTENSIONS ON THE ARRAY
for ($i = 0; $i < count($extension); $i++)
{
if (eregi("\.". $extension[$i] ."$", $file))
{
$files[] = $file;
}
}
}
//CLOSE THE HANDLE
closedir($dir);
//ORDER OF THE ARRAY
if ($reverse) {
rsort($files);
} else {
sort($files);
}
return $files;
}
function GetRandomFile($dirname, $extension = FALSE, $reverse = FALSE)
{
$files = GetFileList($dirname,$extension,$reverse);
$files_randmax = count($files) - 1;
$files_num = rand(0,$files_randmax);
$files_name = $dirname."/".$files[$files_num];
return $files_name;
}
$document_root = ".";
$img_file = GetRandomFile($document_root);
header('Content-type: image/jpeg');
$handle = fopen($img_file, "r");
while (!feof($handle)) {
$buffer = fgets($handle, 4096);
echo $buffer;
}
fclose($handle);
?>