PHP dir() Function
In this chapter you will learn:
- Definition for PHP dir() Function
- Syntax for PHP dir() Function
- Parameter for PHP dir() Function
- Return for PHP dir() Function
- Example - PHP dir() Function reads a directory
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 //ja va 2 s. com
$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.
Next chapter...
What you will learn in the next chapter:
- Definition for PHP dirname() Function
- Syntax for PHP dirname() Function
- Parameter for PHP dirname() Function
- Return for PHP dirname() Function
- Example - Get the directory name from a path
Home » PHP Tutorial » PHP File Functions