PHP opendir() Function
PHP Directory Reference Manual
Example
Open a directory, read its contents, and then close it:
"; } closedir($dh); } } ?>Result:
filename: cat.gif
filename: dog.gif
filename: horse.gif
Definition and Usage
The opendir() function opens a directory handle.
Syntax
opendir(
path,context
);
| Parameters | Description |
|---|---|
| path | Required. Specifies the path of the directory to open. |
| context | Optional. Specifies the context of the directory handle. A context is a set of options that can modify the behavior of a directory stream. |
Technical Details
| Return Value: | Returns a directory handle resource on success, or FALSE on failure. If the path is not a valid directory, or the directory cannot be opened due to permission restrictions or filesystem errors, an E_WARNING level error is raised. You can suppress the error output of opendir() by prefixing the function name with '@'. |
|---|---|
| PHP Version: | 4.0+ |
| PHP Changelog: | PHP 5.0: The path parameter supports ftp:// URL wrapper protocols. |
PHP Directory Reference Manual