/// <summary> /// 保存文件 /// </summary> private UploadIMGModel SaveFile(HttpPostedFile hpf) { if (hpf.ContentLength > 0) { string upladFilesPath = GetUpladFilesPath(); string guidFileName = Guid.NewGuid().ToString(); string fileStorageName = ""; string smallFileName = ""; string fullName = GenPath(hpf.FileName, guidFileName, out fileStorageName); //添加文件路径信息 string retFullName = GenRetPath(hpf.FileName, guidFileName, out fileStorageName); string smallFileAllPath = GenSmallPath(hpf.FileName, guidFileName, out smallFileName); UploadIMGModel retModel = new UploadIMGModel(); retModel.FileRealName = hpf.FileName; retModel.FileSize = (Math.Round((double)hpf.ContentLength / 1024)).ToString(); retModel.FileType = Path.GetExtension(hpf.FileName).ToLower().Replace(".", ""); retModel.FileAllPath = retFullName; retModel.SmallFileVirtuPath = GenSmallVirtuPath(hpf.FileName, guidFileName, out smallFileName); if (!Directory.Exists(upladFilesPath)) { Directory.CreateDirectory(upladFilesPath); } hpf.SaveAs(fullName); //保存上载文件 // BitAuto.Utils.ImageTool.MakeSmallImage(fullName, smallFileAllPath, 200, ImageTool.LimitSideMode.Auto);//保存缩略图 IMGUploadHelper.MakeSmallImage(fullName, smallFileAllPath, 200, ImageTool.LimitSideMode.Auto); //保存缩略图 return(retModel); } else { throw new Exception("没有上传文件"); } }
public void ProcessRequest(HttpContext context) { try { switch (Action) { case "imgImport": if (UserRightsService.CheckLoginUserIDByCookies(LoginCookiesContent) > 0) { string msg = ""; bool flag; UploadIMGModel retModel = UploadOfficeSupplyImg(out msg, out flag); JavaScriptSerializer jsserializer = new JavaScriptSerializer(); AJAXHelper.WrapJsonResponse(flag, msg, jsserializer.Serialize(retModel)); } break; case "deleteIMG": if (UserRightsService.CheckLoginUserIDByCookies(LoginCookiesContent) > 0) { bool flagDel = DeleteIMG(); AJAXHelper.WrapJsonResponse(flagDel, ",请重新删除!", ""); } break; case "getSysLoginCookieName": AJAXHelper.WrapJsonResponse(true, BitAuto.ISDC.CC2012.BLL.Util.SysLoginCookieName, ""); break; default: AJAXHelper.WrapJsonResponse(false, "没有对应的操作", "没有对应的操作"); break; } } catch (Exception ex) { AJAXHelper.WrapJsonResponse(false, "操作失败!", ex.Message); } }
private UploadIMGModel UploadOfficeSupplyImg(out string msg, out bool flag) { msg = ""; flag = true; UploadIMGModel retModel = null; try { HttpPostedFile hpf = System.Web.HttpContext.Current.Request.Files["Filedata"]; if (hpf.ContentLength > 0) { retModel = SaveFile(hpf); } } catch (Exception exp) { msg = "上传图片异常"; flag = false; // BLL.Loger.LogInfo.Error("【上传图片异常】:" + exp.Message); } return(retModel); }