Open a directory, read its contents, then close:
<?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.giffilename: dog.giffilename: horse.gifThe readdir() function returns the file name of the next file in the directory.
readdir( dir_handle );
parameter | describe |
---|---|
dir_handle | Optional. Specifies a directory handle resource previously opened by opendir(). If this parameter is not specified, the last link opened by opendir() is used. |
Return value: | The file name is returned on success, FALSE on failure. |
---|---|
PHP version: | 4.0+ |