Tutorials Infos - Anleitungen - Hilfe - Dreamcodes
 

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");
?>

 
ID: 1492
eingestellt am: 29.10.2007
Autor: Na
Status zum lesen: Gast
gelesen: 4736
Webseite: www.dreamcodes.com
[Drucken]