Open a directory, read its contents, and then close it.
| <?php $dir = “/images/”; // Open a directory, and read its contents if (is_dir($dir)){ if ($dh = opendir($dir)){ while (($file = readdir($dh)) !== false){ echo “filename:” . $file . “<br>”; } closedir($dh); } } ?> |
Result:
| filename: cat.gif filename: dog.gif filename: horse.gif |
The closedir() function closes an open directory handle.
| closedir(dir) |
|
Parameter |
Description |
|
dir |
Optional. Specifies the directory handle resource previously opened with |
|
Return Value: |
– |
|
PHP Version: |
4.0+ |