php获取目录下所有文件路径(递归)

<?php
function tree(&$arr_file, $directory, $dir_name='') 
{

    $mydir = dir($directory);
    while($file = $mydir->read())
    {
        if((is_dir("$directory/$file")) AND ($file != ".") AND ($file != ".."))
        {
            tree($arr_file, "$directory/$file", "$dir_name/$file");
        }
        else if(($file != ".") AND ($file != ".."))
        {
            $arr_file[] = "$dir_name/$file";
        }
    }
    $mydir->close();
}

//开始运行
$arr_file = array();
tree($arr_file, "D:/mydir");
var_dump($arr_file);

  

posted @ 2019-03-22 15:41  zhuzhipeng  阅读(2212)  评论(0编辑  收藏  举报