/** * 遍历目录 * @staticvar int $depth * @staticvar array $path * @param type $dir * @param type $clear 是否销毁静态变量 * @return string|boolean */ public function _scan($dir, $clear = false) { static $depth = 0; static $path = array(); // 无限遍历 // if ($depth >= 10000) { // return false; // } if($clear) { $path = null; static $path = array(); } $dirArr = scandir($dir); foreach ($dirArr as $v) { if (substr($v, 0, 1) != ‘.‘) {//去掉隐藏目录或文件 $dirname = $dir . DS . $v; //子文件夹的目录地址 if (is_dir($dirname)) { $depth++; $this->_scan($dirname); } else { $path[] = $dirname; } } } return $path; }
原文地址:https://www.cnblogs.com/bandbandme/p/11687577.html
时间: 2024-10-20 05:23:33