php 循环打开目录读取文件

function file_list($path)  
{  
    if ($handle = @opendir($path))//打开路径成功  
    {  
        while (false !== ($file = readdir($handle)))//循环读取目录中的文件名并赋值给$file  
        {  
            if ($file != "." && $file != "..")//排除当前路径和前一路径  
            {  
                if (is_dir($path."/".$file))  
                {  
                    file_list($path."/".$file);  
                }  
                else  
                {  
                    echo $path.": ".$file."<br>"; 
                }  
            } 
        } 
    }
    //closedir($handle);  
}
file_list($path);

  

原文地址:https://www.cnblogs.com/zhaozhilu/p/2700364.html