遍历一个目录下的所有文件

    xiaoxiao2021-12-14  19

    function listDir($dir,&$res) { if (is_dir($dir)) { if ($dh = opendir($dir)) { while ((($file = readdir($dh)) !== false)) { if ($file != '..' and $file != '.' and is_dir($dir . "/" . $file)) { //过滤掉有些系统中目录下出现的‘.’和‘..’,因为这两个只是相当于返回当前目录和当前目录的上级目录的快捷键,其本身不是文件也不是mulu listDir($dir . "/" . $file, $res); } elseif ($file != '..' and $file != '.') { $res[] = $dir . "/" . $file; } } closedir($dh); } return $res; } } 测试: $files = array(); listDir('images', $files);
    转载请注明原文地址: https://ju.6miu.com/read-963320.html

    最新回复(0)