php读取目录及子目录下所有文件名的方法

function read_all_dir ( $dir ){

$result = array();
$handle = opendir($dir);//读资源
if ($handle){
while (($file = readdir($handle)) !== false ){
if ($file != ‘.’ && $file != ‘..’){
$cur_path = $dir . DIRECTORY_SEPARATOR . $file;
if (is_dir($cur_path )){//判断是否为目录,递归读取文件
$result[‘dir’][$cur_path] = read_all_dir($cur_path );
}else{
$result[‘file’][] = $cur_path;
}
}
}
closedir($handle);
}
return $result;
}

$file =read_all_dir(‘G:\wamp\www’);
print_r($file);die;
———————
作者:Arnold__
来源:CSDN
原文:https://blog.csdn.net/litchi_yang/article/details/78731115
版权声明:本文为博主原创文章,转载请附上博文链接!

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注