保存web文件

function saveFileFromWeb($http_url , $save_file_path, $MediaType)
 {
	$download_info = load_remote_file($http_url, $save_file_path);

	if($download_info)
	{
		$info = stat($save_file_path);
		$size = $info[7];
		//TODO: add more $MediaType
		$MediaType = strtoupper($MediaType);
		if( !in_array( $MediaType , array( "IMAGE" ) ) )
		{
			return array(false , "This Media type ($MediaType) is not allowed");
		}
		$file_info = getimagesize($save_file_path);
		$w = $file_info[0];
		$h = $file_info[1];
		// save file info to db
		$file_item = array(
			"Name" => basename($save_file_path),
			"Size" => $size,
			"Width" => $w,
			"Height" => $h,
			"MediaType" => $MediaType,
			"PathType" => "LOCALFILE",
			"FilePath" => $save_file_path,
			"Status" => 1,
			"ActiveFlag" => 1,
			"FileTimestamp" => time(),
		);
		return array(true , $file_item);
	}
	else
	{
		return array(false,"try to download[$http_url] to local[$save_file_path] res:". var_export($download_info,true));
	}
 }

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章