greetings all,
I'm gathering image names from a directory and am having a problem :
Code :
<?
$dir = "/image/dir";
function Get_Image_list($dir) {
if(!$dir) {
$dir = ".";
}
$file_array = array();
$dir_handle = opendir($dir);
while($file = readdir($dir_handle)) {
if((preg_match('/jpg/',$file)) ||
(preg_match('/png/',$file)) ||
(preg_match('/gif/',$file)) ||
(preg_match('/jpeg/',$file))) {
array_push($file_array,$file);
}
}
return $file_array;
}
$file_array = Get_Image_list($dir);
$max = count($field_array)-1;
srand((double)microtime()*1000000);
$index = rand(0,$max); // line 24
$file = $file_array[$index];
echo "$file";
?>
Error :
Warning: rand(): Invalid range: 0..-1 in /home/my/dir/index.php on line 24
In Closing :
It does echo one graphic and it's always the oldest dated one and also gives the above error. I've read the rand() manual and various other tidbits of information and cannot figure why $max isn't giving a value, is this the problem?
Frustrated , hopeful and learning,
Philip