List all entries in the images
directory, 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 readdir() function returns the name of the next entry in a directory.
readdir(dir) |
Parameter |
Description |
dir |
Optional. Specifies the directory handle resource previously opened with opendir(). If not provided, the function assumes the last directory handle opened by opendir(). |
Return Value: |
Returns the entry name (filename) on success, or FALSE on failure. |
PHP Version: |
4.0+ |