Open a directory, list its files, reset the directory handle, list the files again, and then close the directory.
<?php $dir = “/images/”; // Open a directory, and read its contents if (is_dir($dir)){ if ($dh = opendir($dir)){ // List files in images directory while (($file = readdir($dh)) !== false){ echo “filename:” . $file . “<br>”; } rewinddir(); // List once again files in images directory while (($file = readdir($dh)) !== false){ echo “filename:” . $file . “<br>”; } closedir($dh); } } ?> |
Result:
filename: cat.gif filename: dog.gif filename: horse.gif filename: cat.gif filename: dog.gif filename: horse.gif |
The rewinddir() function resets the directory handle created by opendir() to the beginning.
rewinddir(dir) |
Parameter |
Description |
dir |
Optional. Specifies the directory handle resource previously opened with |
Return Value: |
Returns |
PHP Version: |
4.0+ |