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;
	}

原文地址:https://www.cnblogs.com/qixidi/p/10206135.html