public ActionResult UploadFile(HttpPostedFileBase files)
{
var result = new ResultDto();
#region 文件存储
if (files != null)
{
if (files.ContentType == "video/mp4" || files.ContentType == "video/x-sgi-movie" || files.ContentType == "video/mpeg" ||
files.ContentType == "video/x-mpg")
{
string floder = Server.MapPath("~/Data/Video/");
if (!Directory.Exists(floder))
{
Directory.CreateDirectory(floder);
}
string filePath = files.FileName;
string path = floder + filePath;
files.SaveAs(path);
Session["path"] = path;
}
else
{
try
{
string floder = Server.MapPath("~/Data/UPStudy/"); //doc,xlsx,ppt
if (!Directory.Exists(floder))
{
Directory.CreateDirectory(floder);
}
string filePath = files.FileName;
string path = floder + filePath;
files.SaveAs(path);
Session["path"] = path;
}
catch(Exception e)
{
result.Success = false;
result.Message = e.Message;
}
}
_dbContext.SaveChanges();
result.Success = true;
result.Message = "上传成功!";
}
#endregion
return Json(result);
}
03-17