The rewinddir() function resets the directory handle created by opendir().
PHP rewinddir() Function has the following syntax.
rewinddir(dir_handle);
Parameter | Is Required | Description |
---|---|---|
dir_handle | Optional. | Directory handle resource previously opened with opendir(). If this parameter is not specified, the last link opened by opendir() is assumed |
Open a directory, list its files, reset directory handle, list its files once again, then close:
<?php/* w w w . ja v a 2s . c o m*/
$dir = "/images/";
if (is_dir($dir)){
if ($dh = opendir($dir)){
// List files in images directory
while (($file = readdir($dh)) !== false){
echo "filename:" . $file . "\n";
}
rewinddir();
// List once again files in images directory
while (($file = readdir($dh)) !== false){
echo "filename:" . $file . "\n";
}
closedir($dh);
}
}
?>