zhangxilong
/*
 * 递归获取文件夹和文件
 * @param   $path 获取的文件夹路径
 * @return  $list array
 * 使用scandir函数可以扫描文件夹下内容 代替while循环读取
 */
function scandirFolder($path){
    $list = [];
    $temp_list = scandir($path);
    foreach ($temp_list as $file){
        if ($file != ".." && $file != "."){
            if (is_dir($path . "/" . $file)){
                //子文件夹,进行递归
                $list[][$file] = scandirFolder($path . "/" . $file);

            }else{
                //根目录下的文件
                $list[] = $file;
            }     

        }
    }
    return $list;
}

结果:

 

分类:

技术点:

相关文章:

  • 2021-12-03
  • 2021-12-03
  • 2021-09-11
  • 2021-12-03
  • 2021-09-11
  • 2021-09-11
  • 2021-09-11
  • 2021-10-10
猜你喜欢
  • 2021-12-03
  • 2021-09-11
  • 2021-09-11
  • 2021-08-31
  • 2021-11-28
  • 2021-12-03
  • 2021-09-11
相关资源
相似解决方案