note 21221 added to function.readdir

From: Date: Fri, 03 May 2002 17:28:37 +0000
Subject: note 21221 added to function.readdir
Groups: php.notes 
Request: Send a blank email to php-notes+get-30130@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]>"; ?> -- http://www.php.net/manual/en/function.readdir.php http://master.php.net/manage/user-notes.php?action=edit+21221 http://master.php.net/manage/user-notes.php?action=delete+21221 http://master.php.net/manage/user-notes.php?action=reject+21221

« previous php.notes (#30130) next »