1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39 |
//获取文件目录列表,该方法返回数组 function
getDir($dir) { $dirArray[]=NULL; if
( false
!= ($handle = opendir ( $dir ))) { $i=0; while
( false
!== ($file = readdir ( $handle )) ) { //去掉""."、".."以及带".xxx"后缀的文件 if
($file != ". " && $file != " .. "&&!strpos($file," . ")) { $dirArray[$i]=$file; $i++; } } //关闭句柄 closedir ( $handle ); } return $dirArray; } //获取文件列表 function getFile($dir) { $fileArray[]=NULL; if (false != ($handle = opendir ( $dir ))) { $i=0; while ( false !== ($file = readdir ( $handle )) ) { //去掉" "." 、 ".." 以及带 ".xxx" 后缀的文件 if
($file != "."
&& $file != ".." &&strpos($file, "." )) { $fileArray[$i]=$file; //echo($file); if ($i==100){ break ; } $i++; } } //关闭句柄 closedir ( $handle ); } return
$fileArray; } |
输出
1
2
3
4
5 |
$font_list =getFile( "../fonts/fontfile/" ); //获取数组值 foreach ( $font_list
as $software ) //遍历数组并输出 { echo $software . "//" ; } |
PHP读取文件夹所有文件并输出,布布扣,bubuko.com
原文:http://www.cnblogs.com/keringing/p/3577264.html