closedir()

本页内容

PHP closedir() 函数

Category:PHP Directory 文件目录参考手册

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


示例

<?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+

Category:PHP Directory 文件目录参考手册

此页面最后编辑于2022年8月17日 (星期三) 22:14。