PHP 遍历获取文件夹内所有文件路径


 

function xmsb_getPathList($path)
{
    $result = [];

    $paths = scandir($path);
    foreach($paths as $item)
    {
        if($item != '.' && $item != '..')
        {
            $encode = mb_detect_encoding($item, ['ASCII', 'UTF-8', "GB2312", "GBK", 'BIG5']);
            $item = mb_convert_encoding($item, 'UTF-8', $encode);
            $fullpath = $path . '/' . $item;

            if(is_dir($fullpath))
            {
                clearstatcache();

                $result[$item] = xmsb_getPathList($fullpath);
            }
            else
            {
                $result[$item] = $fullpath;
            }
        }
    }

    return $result;
}

 

posted @ 2022-04-10 18:06  何效名  阅读(408)  评论(0编辑  收藏  举报