PHP closedir() Function
In this chapter you will learn:
- Definition for PHP closedir() Function
- Syntax for PHP closedir() Function
- Parameter for PHP closedir() Function
- Example - Open a directory, read its contents, then close
Definition
The closedir() function closes a directory handle.
Syntax
PHP closedir() Function has the following syntax.
closedir(dir_handle);
Parameter
Parameter | Is Required | Description |
---|---|---|
dir_handle | Optional. | Directory handle resource previously opened with opendir(). If not specified, the last link opened by opendir() is used |
Example
Open a directory, read its contents, then close:
<?php/*from j a v a 2 s. c o m*/
$dir = "/data/";
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 copy() Function
- Syntax for PHP copy() Function
- Parameter for PHP copy() Function
- Note for PHP copy() Function
- Return value from PHP copy() Function
- Example - Files are copied using copy()
- Example - Copy a file
Home » PHP Tutorial » PHP File Functions