public ActionResult UploadImage() { var files = HttpContext.Request.Files; if (files == null || files.Count < 1) { return(Json(new LayuiUploadImageOut(1, "没有找到上传图片"))); } UploadParameter p = new UploadParameter(files[0]); string path = "/UploadFiles/ArticleImages/{0}/{1}"; path = string.Format(path, DateTime.Now.ToDateString(), p.GetDefaultFileName()); p.SavePath = HttpContext.Server.MapPath(path); var result = UploadHelper.UploadFile(UploadType.IMAGE, p); if (result.Status == UploadStatus.Success) { var image = new LayuiUploadImageOut(0, result.Msg, path); return(Json(image)); } else { var image = new LayuiUploadImageOut(1, result.Msg); return(Json(image)); } }
public AjaxResult UploadUserFace() { HttpFileCollection files = HttpContext.Current.Request.Files; if (files == null || files.Count < 1) { return(new AjaxResult(false, "没有找到上传文件")); } UploadParameter p = new UploadParameter(); string tempPath = "/UploadFiles/UserFace"; string resultPath = ""; try { bool success = true; string msg = ""; for (int i = 0; i < files.Count; i++) { var file = files[i]; p.File = new HttpPostedFileWrapper(file); string fileName = p.GetDefaultFileName(); string path = string.Format("{0}/{1}", tempPath, fileName); p.SavePath = HttpContext.Current.Server.MapPath(path); var result = UploadHelper.UploadFile(UploadType.IMAGE, p); if (result.Status == UploadStatus.Success) { success = true; resultPath = path; } else { success = false; } msg = result.Msg; } return(new AjaxResult(success, msg, resultPath)); } catch (Exception e) { return(new AjaxResult(false, "上传失败" + e.Message)); } }