PHP 教程 PHP closedir() 函数

bishop · 2022-03-07 11:06:13 · 热度: 7

实例

打开一个目录,读取它的内容,然后关闭:

<?php
$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 . "<br>";
}
closedir($dh);
}
}
?>

结果:

filename: cat.gif
filename: dog.gif
filename: horse.gif

定义和用法

closedir() 函数关闭目录句柄。

语法

closedir(dir_handle);

参数 描述
dir_handle 可选。指定之前由 opendir() 打开的目录句柄资源。如果该参数未指定,则使用最后一个由 opendir() 打开的链接。

技术细节

返回值: -
PHP 版本: 4.0+

查看更多 PHP Directory 函数

猜你喜欢:
暂无回复。
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册