php 获取目录下所有文件实现代码

  1. class a{
  2. private $img_dir;
  3. private $img_path;
  4. private $face_files = array();
  5. private $allow_extension = array();
  6. private function get_face_files()
  7. {
  8. $files = array();
  9. if(is_dir($this->img_dir))
  10. {
  11. if ($dh = opendir($this->img_dir))
  12. {
  13. while (($file = readdir($dh)) !== false)
  14. {
  15. if($file == '.') continue;
  16. if($file == '..') continue;
  17. $fileinfo = explode('.', (basename($file)));
  18. if(in_array($fileinfo[1], $this->allow_extension))
  19. {//开源代码phpfensi.com
  20. $files[] = array(
  21. 'filename' => $fileinfo[0],
  22. 'extension' => $fileinfo[1],
  23. );
  24. }
  25. }
  26. closedir($dh);
  27. }
  28. }
  29. return $files;
  30. }
  31. }