PHP readdir() Function
Example
Open a directory, read its content, and then close it:
<?php $dir = "/images/"; // Open the directory and then read its content 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
Definition and Usage
The readdir() function returns the filename of the next file in the directory.
Syntax
readdir(dir_handle);
Parameter | Description |
---|---|
dir_handle |
Optional. Specify the directory handle resource opened by opendir() previously. If this parameter is not specified, the last link opened by opendir() is used. |
Technical Details
Return Value: | Returns the name of the entry (filename) if successful, or FALSE if unsuccessful. |
---|---|
PHP Version: | 4.0+ |