上传文件帮助类

/// <summary>
	/// 文件上传帮助类
	/// </summary>
	public class UploadHelper
	{
		/// <summary>
		/// 附件上传 成功:succeed、失败:error、文件太大:-1、
		/// </summary>
		/// <param name="file">单独文件的访问</param>
		/// <param name="path">存储路径</param>
		/// <param name="filename">输出文件名</param>
		/// <returns></returns>
		public static string FileUpload(HttpPostedFileBase file, string path, string filename)
		{
			bool flag = !Directory.Exists(path);
			if (flag)
			{
				Directory.CreateDirectory(path);
			}
			string result;
			try
			{
				int num = file.ContentLength / 1024 / 1024;
				bool flag2 = num > 10;
				if (flag2)
				{
					result = "-1";
				}
				else
				{
					file.SaveAs(path + filename);
					result = "succeed";
				}
			}
			catch (Exception ex)
			{
				result = ex.Message;
			}
			return result;
		}
	}
posted @ 2022-07-26 20:16  码农阿亮  阅读(45)  评论(0编辑  收藏  举报