note 46603 added to function.readdir
| From: | rpkamath at gmail dot com | Date: | Sun, 17 Oct 2004 01:04:32 +0000 |
| Subject: | note 46603 added to function.readdir | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-78678@lists.php.net to get a copy of this message | ||
I'm not a PHP guru, so there may be a bug in this, but I thought this readdir based "image
slideshow" might be useful to someone out there. Borrowing some of the aforementioned code, I
made a tool that, given a directory of image files, will display one item per page, and will give
the user the ability to click through the entire directory of images. That is, when you click an
item, the page will refresh with the next image in line, until it gets to the last image, whereupon
it will stop and the image on the page can't be clicked anymore. If any files are in the
directory that are not images or called index.php, you will experience problems, and will have to
change some of the code. Thanks to "nick_vollebergh", whose code I borrowed in this.
<?php
$the_array = Array();
$handle = opendir('.');
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != ".." && $file !=
"index.php") {
$the_array[] = $file;
}
}
closedir($handle);
if (!$item) { ($item = 0 ) ; }
$item2 = $item+1;
if ($item < (count($the_array))-1) {
print ("<A HREF = 'index.php?item=$item2'><IMG SRC =
'$the_array[$item]' border=1></A>");
} else {
print ("<IMG SRC = '$the_array[$item]'>") ;
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.readdir.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+46603
Delete -- http://master.php.net/manage/user-notes.php?action=delete+46603&report=yes
Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+46603&report=yes&reason=bad+code
Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+46603&report=yes&reason=spam
Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+46603&report=yes&reason=useless+example
Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+46603&report=yes&reason=contains+commercial+links
Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+46603&report=yes&reason=useless+note
Reject -- http://master.php.net/manage/user-notes.php?action=reject+46603&report=yes
Search -- http://master.php.net/manage/user-notes.php