note 46603 deleted from function.readdir by tomsommer
| From: | tomsommer@php.net | Date: | Sun, 17 Oct 2004 01:14:19 +0000 |
| Subject: | note 46603 deleted from function.readdir by tomsommer | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-78679@lists.php.net to get a copy of this message | ||
Note Submitter: rpkamath at gmail dot com
----
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]'>") ;
}
?>