Php opendir open directory function
PHP 4, PHP 5)
Opendir-Open Directory handle
Report error description
Resource opendir (string $ path [, resource $ background])
A directory handle is opened for subsequent closedir (), readdir (), and rewinddir () calls.
Definition and usage
The opendir () function opens a directory handle, which can be used by closedir (), readdir (), and rewinddir.
If the operation succeeds, the function returns a directory stream. Otherwise, false and an error are returned. You can add "@" before the function name to hide the error output.
Report error parameters
Path
The directory path is to open
Context
For context parameter descriptions, see the flow section in the manual.
<? Php
$ Dir = "/etc/php5 /";
// Open a known directory, and proceed to read its contents
If (is_dir ($ dir )){
If ($ dh = opendir ($ dir )){
While ($ file = readdir ($ dh ))! = False ){
Echo "filename: $ file: filetype:". filetype ($ dir. $ file). "n ";
}
Closedir ($ dh );
}
}
?>
The above example will output something similar:
Filename:.: filetype: dir
Filename: ..: filetype: dir
Filename: apache: filetype: dir
Filename: cgi: filetype: dir
Filename: cli: filetype: dir
Report error return value
Returns the success or FALSE of the failed resource of the directory handle.
If the path is not a valid directory or the directory cannot be opened, opendir () returns FALSE due to permission restrictions or file system errors, and generates an E_WARNING-level PHP error. You can suppress adding the '@' function name before the opendir error output.
Report error update log
Version description
5.0.0 supports the ftp: // URL protocol.
The 4.3.0 path can also be any URL that supports the directory list, but only the File: // URL protocol supports