background image

php 自定义函数:PHP 遍历文件夹下的所有目录及文

$path = ‘./filepath’;  
  function getfiles($path)  
  {  
      if(!is_dir($path)) return;  
     $handle  = opendir($path);  
     while( false !== ($file = readdir($handle)))  
     {  
         if($file != ‘.’  &&  $file!=’..’)  
         {  
             $path2= $path.’/’.$file;  
             if(is_dir($path2))  
             {  
                 echo ”;  
                 echo $file;  
                getfiles($path2);  
             }else 
             {  
                echo ”;  
                 echo $file;  
             }  
         }  
     }  
 }  
print_r( getfiles($path));  
echo ‘ <HR>’;  
 function getdir($path)  
 {  
     if(!is_dir($path)) return;  
     $handle = dir($path);  
     while($file=$handle-&gt;read())  
     {  
         if($file!=’.’ &amp;&amp; $file!=’..’)  
         {