php 获取文件目录下的文件和子文件 、包括显示出指定的文件名后缀文件。

 1 /* 获取文件目录下的文件和子文件*/
 2 
 3 function getfile($path){
 4     
 5     foreach(glob($path.'\*' as $file)){
 6        
 7         echo $file;
 8 //判断$file 是否是目录 ,是目录递归再次遍历
 9     if(is_dir($file)){
10            getfile($path) 
11           
12         }
13     }
14 
15 }
16 
17 
18 /*获取文件目录下指定后缀名的文件*/    
19 
20 
21 function getFileName($path){
22       
23        foreach(glob($path.'\*' as $file)){
24          $i = 0;
25          if(preg_match('/.png$/',$file)){
26              $fileArr[$is] = $file;
27              print_r($fileArr); 
28            }
29            if(is_dir($file)){
30            getFileName($path);
31        }
32 
33 
34     }
35 
36 
37 }
38                 

 

posted @ 2017-05-25 10:33  大咸菜·  阅读(2098)  评论(0编辑  收藏  举报