PHP closedir() Function
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//w w w .j av a2 s . co m
$dir = "/data/";
if (is_dir($dir)){
if ($dh = opendir($dir)){
while (($file = readdir($dh)) !== false){
echo "filename:" . $file . "\n";
}
closedir($dh);
}
}
?>