This function is used to display random image i.e. at header position of a site. It reads the whole directory and then randomly print the image. I think it may be useful for someone.
<?php
if ($handle = opendir('images/')) {
$dir_array = array();
while (false !== ($file = readdir($handle))) {
if($file!="." && $file!=".."){
$dir_array[] = $file;
}
}
echo $dir_array[rand(0,count($dir_array)-1)];
closedir($handle);
}
?>