Zufalls Bild
Zufällige Grafik aus einem Verzeichniss ermitteln
|
Script: |
<?
function getRandomImageFileName($path)
{
$result =
"";
$ar =
array();
$handle=opendir($path);
while ($file =
readdir ($handle))
{
if ($file
!= "."
&& $file
!= "..")
{
if (! is_dir($file))
{
$sub
= substr($file,
-4);
if
($sub == ".png"
|| $sub ==
".jpg" ||
$sub == ".gif"
|| $sub ==
".bmp")
$ar[]
= $file;
}
}
}
closedir($handle);
$max =
count($ar);
if ($max >
0)
{
srand
((double)microtime()*1000000);
$max
-= 1;
$p
= rand(0,$max);
$result
= $ar[$p];
}
return $result;
}
$fileName =
getRandomImageFileName("./images");
?>
|
|