The dir() function returns an instance of the Directory class.
PHP dir() Function has the following syntax.
dir(directory,context);
Parameter | Is Required | Description |
---|---|---|
directory | Required. | Directory to open |
context | Optional. | Context to use |
PHP dir() Function returns an instance of the Directory class. FALSE on failure.
Use the dir() function to read a directory:
<?php /*w w w . j a va 2 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.