note 90770 modified in function.readdir by danbrown

From: Date: Fri, 08 May 2009 19:09:24 +0000
Subject: note 90770 modified in function.readdir by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-154375@lists.php.net to get a copy of this message
Thought I would include what I wrote to get a random image from a directory. <?php $count = 0; if ($handle = opendir('image_dir)) { $retval = array(); while (false !== ($file = readdir($handle))) { if (($file <> ".") && ($file <> "..")) { $retval[$count] = $file; $count = $count + 1; } } closedir($handle); } shuffle($retval); $current_image = $retval[0]; ?> --was-- Thought I would include what I wrote to get a random image from a directory. Any comments/suggestions are always welcome. <?php $count = 0; if ($handle = opendir('image_dir)) { $retval = array(); while (false !== ($file = readdir($handle))) { if (($file <> ".") && ($file <> "..")) { $retval[$count] = $file; $count = $count + 1; } } closedir($handle); } shuffle($retval); $current_image = $retval[0]; ?> http://php.net/manual/en/function.readdir.php

« previous php.notes (#154375) next »