1./**
2.* 获取指定目录下的文件列表
3.* string $path 指定的目录,默认为当前目录
4.* string $exten 文件扩展名带前面的点(.txt),默认显示全部文件
5.* string $ifchild 是否显示子目录文件列表,默认不显示
6.*/
7.function openpath($path=".", $exten = '*' ,$ifchild = false){
8. $array = array();
9. static $file_array=array(); //存放文件名数组
10. static $path_array=array(); //存放路径数组(不包括文件名)
11. $path = preg_replace('/(.*)([^\/])$/', '$1$2/', $path);
12. if(is_dir($path)){ //检查文件目录是否存在
13. $H = @ opendir($path);
14. while(false !== ($_file=readdir($H))){
15. //检索目录
16. if(is_dir($path.$_file) && $_file != "." && $_file!=".." && $_file!=="Thumbs.db"){
17. if($ifchild){
18. openpath($path.$_file, $exten ,$ifchild);
19. }
20. //检索文件
21. }elseif(is_file($path.$_file) && $_file!="." && $_file!=".." && $_file!=="Thumbs.db"){
22. //$_file = auto_charset($_file,'utf-8','gbk');
23. if($exten == '*'){
24. array_push($file_array, $_file);
25. array_push($path_array, $path);
26. } else {
27. if(preg_match('/(.*)'.$exten.'/', '/'.$_file.'/')){
28. array_push($file_array, $_file);
29. array_push($path_array, $path);
30. }
31. }
32. }
33. }
34. closedir($H);
35. }
36. $array['name'] = $file_array;
37. $array['path'] = $path_array;
38. return $array;
39.}