PHP搜索文件夹下全部文件


搜索文件夹下全部文件


//搜索文件夹下全部文件,暂时不支持中文文件名
	public function scanFile($path) {
		if (!is_dir($path))
			return array();
		// 兼容各操作系统
		$path = rtrim(str_replace('\\','/',$path ),'/').'/';
	  	$result = array();
		$files = scandir($path);
		foreach ($files as $file) {
			if ($file != '.' && $file != '..') {
				$file=iconv("gb2312","utf-8",$file);
				if (is_dir($path . '/' . $file)) {
					$result = array_merge($result, scanFile($path . '/' . $file));
				} else {
					$result[] = basename($file);
				}
			}
		}
		return $result;
	}

posted @ 2019-01-01 21:35  栖息地  阅读(415)  评论(0编辑  收藏  举报