note 89582 added to function.readdir
| From: | hanan dot ali dot shaikh at gmail dot com | Date: | Sun, 15 Mar 2009 07:37:46 +0000 |
| Subject: | note 89582 added to function.readdir | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-151956@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))];
closedir($handle);
}
?>
----
Server IP: 69.147.83.197
Probable Submitter: 119.153.37.79
----
Manual Page -- http://www.php.net/manual/en/function.readdir.php
Edit -- https://master.php.net/note/edit/89582
Del: integrated -- https://master.php.net/note/delete/89582/integrated
Del: useless -- https://master.php.net/note/delete/89582/useless
Del: bad code -- https://master.php.net/note/delete/89582/bad+code
Del: spam -- https://master.php.net/note/delete/89582/spam
Del: non-english -- https://master.php.net/note/delete/89582/non-english
Del: in docs -- https://master.php.net/note/delete/89582/in+docs
Del: other reasons-- https://master.php.net/note/delete/89582
Reject -- https://master.php.net/note/reject/89582
Search -- https://master.php.net/manage/user-notes.php