note 21221 deleted from function.readdir by philip

From: Date: Fri, 08 Nov 2002 01:54:26 +0000
Subject: note 21221 deleted from function.readdir by philip
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-39114@lists.php.net to get a copy of this message
To pull a random .jpg from a directory, you can use this code. I'm sure if can be optimized, but it works: <? $dh = opendir("/path/to/images"); while (false !== ($file = readdir($dh))) { if (preg_match('/\.jpg$/i', $file)) { $filelist[] = $file; } } srand((double)microtime()*1000000); $picnum = rand(0, sizeof($filelist) - 1); echo "<img src=$filelist[$picnum]>"; ?>

« previous php.notes (#39114) next »