PHP dir()Functions
PHP Directory Reference Manual
Examples
Use the dir() function:
<?php
$d = dir(getcwd());
echo "Handle: " . $d->handle . "<br>";
echo "Path: " . $d->path . "<br>";
while (($file = $d->read()) !== false){
echo "filename: " . $file . "<br>";
}
$d->close();
?>
$d = dir(getcwd());
echo "Handle: " . $d->handle . "<br>";
echo "Path: " . $d->path . "<br>";
while (($file = $d->read()) !== false){
echo "filename: " . $file . "<br>";
}
$d->close();
?>
Result:
Handle: Resource id #2
Path: /etc/php
filename: .
filename: ..
filename: ajax.gif
filename: books.xml
filename: cdcatalog.xml
filename: cd_catalog.xml
filename: default.html
filename: demo_array.html
filename: demo_array.htm
...
...
...
Path: /etc/php
filename: .
filename: ..
filename: ajax.gif
filename: books.xml
filename: cdcatalog.xml
filename: cd_catalog.xml
filename: default.html
filename: demo_array.html
filename: demo_array.htm
...
...
...
Definition and Usage
The dir() function returns an instance of the Directory class. This function is used to read a directory, including the following:
- The given directory to be opened
- The handle and path properties of dir() are available
- The handle and path properties have three methods: read(), rewind(), and close()
Syntax
dir(directory,context);
| Parameters | Description |
|---|---|
| directory | Required. Specifies the directory to open. |
| context | Optional. |
Technical Details
| Return value: | Returns an instance of the Directory class. Returns FALSE on failure. |
|---|---|
| PHP Version: | 4.0+ |
PHP Directory Reference Manual Other extensions