<?PHP
/* this will take the directory you call an dreturn a random file in it */
function randompic ($dir)
{ /* this opens the directory and reads its contents into an array called $logo */
$handle=opendir($dir);
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$logo[] = $file;
}
}
/* gets a random filename out of the $logo array */ $randArrayKey = array_rand($logo); $randFile = $logo[$randArrayKey];
/* puts the directory and the filename together */ $path = $dir . $randFile;
/* returns the full path of the file */ return($path);
} ?>
|
|