php获取文件夹中文件

使用 scandir函数 可以扫描文件夹下内容

<?php
class DirPath{
    function scandirFolder($path)
    {
        $list     = [];
        $temp_list = scandir($path);
        foreach ($temp_list as $file)
        {
            //排除根目录
            if ($file != ".." && $file != ".")
            {
                if (is_dir($path . "\\" . $file))
                {
                    //子文件夹,进行递归
                    $list[$file] = self::scandirFolder($path . "\\" . $file);
                }
                else
                {
                    //根目录下的文件
                    $list[] = $file;
                }
            }
        }
        return $list;
    }
}

 $dir = new DirPath();
 $res = $dir->scandirFolder(__DIR__.'\11');
echo '<pre>';
    print_r($res);
echo '<pre>';

猜你喜欢

转载自www.cnblogs.com/clubs/p/12650183.html