在PHP中,目录函数 closedir() 用于关闭目录句柄。
函数语法:
void closedir ( resource $dir_handle )
函数参数说明:
| 参数 | 描述 |
|---|---|
| dir_handle | 可选。指定之前由 opendir() 打开的目录句柄资源。如果该参数未指定,则使用最后一个由 opendir() 打开的链接。 |
closedir() 函数用于关闭目录句柄,关闭由 dir_handle 指定的目录流。流必须之前被 opendir() 所打开。如果目录句柄没有指定,那么会假定为是opendir()所打开的最后一个句柄。
示例:
<?php
$path = 'E:\soft';
if (is_dir($path)) {
// 打开目录句柄
$res = @opendir($path);
// 读取文件条目
while (false !== ($file = readdir($res))) {
if ($file != '.' && $file != '..') {
echo $file . '<br>';
}
}
// 重置目录句柄
rewinddir($res);
if ($file = readdir($res)) {
echo '重置成功';
} else {
echo '重置失败';
}
// 关闭目录句柄
closedir($res);
}
以上代码打开目录,输出目录中的条目,重置目录句柄,最后关闭目录句柄。
803

被折叠的 条评论
为什么被折叠?



