The closedir() function closes a directory handle.
PHP closedir() Function has the following syntax.
closedir(dir_handle);
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 |
Open a directory, read its contents, then close:
<?php//from w w w . j a v a 2s . co m
$dir = "/data/";
if (is_dir($dir)){
if ($dh = opendir($dir)){
while (($file = readdir($dh)) !== false){
echo "filename:" . $file . "\n";
}
closedir($dh);
}
}
?>