1 <?php 2 /** 3 * 获取目录中所有文件的路径 4 * @param $dir 5 * @return array 6 */ 7 public function my_scandir($dir) 8 { 9 if(is_dir($dir)){ 10 $files = array(); 11 $child_dirs = scandir($dir); 12 foreach($child_dirs as $child_dir){ 13 //‘.‘和‘..‘是Linux系统中的当前目录和上一级目录,必须排除掉, 14 //否则会进入死循环,报segmentation falt 错误 15 if($child_dir != ‘.‘ && $child_dir != ‘..‘){ 16 if(is_dir($dir.‘/‘.$child_dir)){ 17 $files[$child_dir] = $this->my_scandir($dir.‘/‘.$child_dir); 18 }else{ 19 $files[] = $child_dir; 20 } 21 } 22 } 23 return $files; 24 }else{ 25 return $dir; 26 } 27 }
原文:https://www.cnblogs.com/pyspang/p/9481997.html