/*
Created By:
Josh Santomieri
Santomieri Systems
http://www.santsys.com
Random image from a directory script
*/
function make_seed()
{
list($usec, $sec) = explode(' ', microtime());
return (float) $sec + ((float) $usec * 100000);
}
function rand_img($img_path = "./images/", $dont_show = array('.','..','thumbs.db'), $file_types = array('jpg','gif','png'))
{
// img_path must have slash '/' after it
//$img_path = "./images/";
//$dont_show = array('.','..','thumbs.db');
//$file_types = array('jpg','gif','png');
$type_ok = 0;
$show_ok = 1;
if($handle = opendir($img_path))
{
$file_array = array("");
while(false !== ($file = readdir($handle)))
{
if(!is_dir($img_path.$file))
{
// make sure the file has the right extension
$file_info = pathinfo($img_path.$file);
for($i = 0; $i < count($file_types); $i++)
{
if($file_info["extension"] == $file_types[$i])
{
$type_ok = 1;
break;
}
}
if(($type_ok))
{
for($i = 0; $i < count($dont_show); $i++)
{
if($file == $dont_show[$i])
{
$show_ok = 0;
break;
}
}
}
if($type_ok && $show_ok)
{
echo "\"$file\"
";
array_push($file_array, $file);
}
}
}
srand(make_seed());
$randval = rand(1, count($file_array)-1);
echo "";
closedir($handle);
}
else
{
echo "Could Not Open Directory '".$img_path."'.\r\n";
}
}
rand_img();