天天看點

周遊檔案夾下的所有檔案

/**
 * 使用scandir 周遊目錄并傳回所有檔案絕對路徑
 *
 * @param $path
 * @return array
 */
function getFile($path)
{
	//判斷目錄是否為空
	if(!file_exists($path)) {
		return array();
	}

	$files = scandir($path);
	$fileItem = array();
	foreach($files as $v) {
		$newPath = $path .DIRECTORY_SEPARATOR . $v;
		if(is_dir($newPath) && $v != '.' && $v != '..') {
			$fileItem = array_merge($fileItem, getFile($newPath));
		}else if(is_file($newPath)){
			$fileItem[] = $newPath;
		}
	}
	return $fileItem;
}