note 89582 modified in function.readdir by danbrown

From: Date: Sun, 15 Mar 2009 14:52:57 +0000
Subject: note 89582 modified in function.readdir by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-151966@lists.php.net to get a copy of this message
This function is used to display random image i.e. at header position of a site. It reads the whole directory and then randomly print the image. I think it may be useful for someone. <?php if ($handle = opendir('images/')) { $dir_array = array(); while (false !== ($file = readdir($handle))) { if($file!="." && $file!=".."){ $dir_array[] = $file; } } echo $dir_array[rand(0,count($dir_array)-1)]; closedir($handle); } ?> --was-- This function is used to display random image i.e. at header position of a site. It reads the whole directory and then randomly print the image. I think it may be useful for someone. <?php if ($handle = opendir('images/')) { $dir_array = array(); while (false !== ($file = readdir($handle))) { if($file!="." && $file!=".."){ $dir_array[] = $file; } } echo $dir_array[rand(0,count($dir_array))]; closedir($handle); } ?> http://php.net/manual/en/function.readdir.php

« previous php.notes (#151966) next »