PHP dir() Function
Definition
The dir() function returns an instance of the Directory class.
Syntax
PHP dir() Function has the following syntax.
dir(directory,context);
Parameter
Parameter | Is Required | Description |
---|---|---|
directory | Required. | Directory to open |
context | Optional. | Context to use |
Return
PHP dir() Function returns an instance of the Directory class. FALSE on failure.
Example
Use the dir() function to read a directory:
<?php /*from w ww .j av a2 s . c o m*/
$d = dir(getcwd());
echo "Handle: " . $d->handle . "\n";
echo "Path: " . $d->path . "\n";
while (($file = $d->read()) !== false){
echo "filename: " . $file . "\n";
}
$d->close();
?>
The code above generates the following result.