PHP rewinddir() Function
Definition
The rewinddir() function resets the directory handle created by opendir().
Syntax
PHP rewinddir() Function has the following syntax.
rewinddir(dir_handle);
Parameter
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 |
Example
Open a directory, list its files, reset directory handle, list its files once again, then close:
<?php/*from w w w . j a v a2s. 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);
}
}
?>