Learning PHP
Advanced PHP
PHP Function Reference
PHP Useful Resources
Selected Reading
© 2011 TutorialsPoint.COM
|
PHP Function dir()
Syntax
dirhandle bool dir ( string $directory )
|
Definition and Usage
The dir() function opens a directory handle and returns an object. The object contains three methods called read() , rewind() , and close() .
Paramters
Parameter | Description |
directory | Required. The directory to be opened. |
Return Value
Returns directory handle on success or FALSE on failure.
Example
Following is the usage of this function:
<?php
$d = dir("/var/www/");
echo "Handle: " . $d->handle . "\n";
echo "Path: " . $d->path . "\n";
while (false !== ($entry = $d->read())) {
echo $entry."\n";
}
$d->close();
?>
|
This will produce following result:
Handle: Resource id #2
Path: /var/www/
.
..
tutorialspoint
images
home
|
|
|
|