PHP rewinddir()Functions

PHP DirectoryPHP Directory Reference Manual

Examples

Open a directory, list the files in it, reset the directory handle, list the files again, and then close it:

<?php $dir = "/images/"; //Open a directory and read its contents if (is_dir($dir)){ if ($dh = opendir($dir)){ //List the files in the images directory while (($file = readdir($dh)) !== false){ echo "filename:" . $file . "<br>"; } rewinddir(); //List the files in the images directory again 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


Definition and Usage

The rewinddir() function resets theopendir()created directory handle.


Syntax

rewinddir(dir_handle);

Parameters Description
dir_handle Optional. Specifies the previouslyopendir()opened directory handle resource. If this parameter is not specified, then the last link opened by opendir() is used.

Technical Details

Return Value: -
PHP Version: 4.0+


PHP DirectoryPHP Directory Reference Manual Other Extensions