PHP opendir() Function
In this chapter you will learn:
- Definition for PHP opendir() Function
- Syntax for PHP opendir() Function
- Parameter for PHP opendir() Function
- Return for PHP opendir() Function
- Example - Open a directory, read its contents, then close
Definition
The opendir() function opens a directory handle.
Syntax
PHP opendir() Function has the following syntax.
opendir(path,context);
Parameter
Parameter | Is Required | Description |
---|---|---|
path | Required. | Directory path to be opened |
context | Optional. | Context of the directory handle. |
Return
PHP opendir() Function returns the directory handle resource on success. FALSE on failure.
Example
Open a directory, read its contents, then close:
<?php// ja va2s.com
$dir = "/images/";
// Open a directory, and read its contents
if (is_dir($dir)){
if ($dh = opendir($dir)){
while (($file = readdir($dh)) !== false){
echo "filename:" . $file . "\n";
}
closedir($dh);
}
}
?>
Next chapter...
What you will learn in the next chapter:
- Definition for PHP parse_ini_file() Function
- Syntax for PHP parse_ini_file() Function
- Parameter for PHP parse_ini_file() Function
- Return for PHP parse_ini_file() Function
- Format of init file
- Example - Parse an ini file
Home » PHP Tutorial » PHP File Functions