private readonly int waterTransparency = 40; //水印图片透时度 /// <summary> /// 图片上传 /// </summary> /// <param name="postedFile"></param> /// <param name="isWater"></param> /// <returns></returns> public string fileSaveAs(HttpPostedFile postedFile, int isWater) { try { string fileExt = postedFile.FileName.Substring(postedFile.FileName.LastIndexOf(".") + 1); if (!FileHelper.CheckFileExt(this.fileType, fileExt)) { return("不允许上传" + fileExt + "类型的文件"); } if (this.fileSize > 0 && postedFile.ContentLength > fileSize * 1024) { return("文件超过限制的大小啦"); } UpLoadMedia.MediaSize = postedFile.ContentLength / 1024; string toFile = string.Format("/upimg/{0:yyyyMM}/{0:ddHHmmssfff}.{1}", DateTime.Now, fileExt); byte[] Data = new byte[1]; Data = FileHelper.AddImageSignPic(File.ReadAllBytes(postedFile.FileName), toFile, WaterPath, WaterPostion, waterQuality, waterTransparency, isWater); FileServer.CreateFileImage(Data, toFile); UpLoadMedia.UploadPath = toFile; return("操作成功"); } catch { return("上传过程中发生意外错误!"); } }
public void ProcessRequest(HttpContext context) { // Loger.Info("-----------这里出错了,还是js出错了!"); context.Response.ContentType = "text/plain"; HttpPostedFile file = context.Request.Files["Filedata"];//接受文件 string fileExt = file.FileName.Substring(file.FileName.LastIndexOf(".") + 1); if (!FileHelper.CheckFileExt(this.fileType, fileExt)) { context.Response.Write("不允许上传" + fileExt + "类型的文件"); } if (this.fileSize > 0 && file.ContentLength > fileSize * 1024) { context.Response.Write("文件超过限制的大小啦"); } filename = DateTime.Now.ToString("ddHHmmssfff") + Path.GetExtension(file.FileName); string folder = DateTime.Now.ToString("yyyyMM"); localPath = HttpContext.Current.Request.PhysicalApplicationPath + ("upimg/" + folder + "/"); //判断文件夹是否存在, 不存在则创建 if (!System.IO.Directory.Exists(localPath)) { System.IO.Directory.CreateDirectory(localPath); } try { //本地创建上传的图片文件 file.SaveAs(Path.Combine(localPath, filename)); } catch (Exception) { strfile = "Error"; } string path = "/upimg/" + folder + "/" + filename; byte[] Data = new byte[1]; Data = FileHelper.AddImageSignPic(File.ReadAllBytes(localPath + filename), path, "", 0, 100, 100, 0); //读取本地图片, 转成二进制, 调用服务生成图片, 返回路径另上域名 if (FileServer.CreateFileImage(Data, path)) { strfile = "http://img.upchina.com" + path; } else { strfile = "Error"; } context.Response.Write("/upimg/" + folder + "/" + filename); }
public void ProcessRequest(HttpContext context) { int MediaClassId = 0; string MediaScale = ""; int smallPiexl = 0; int WaterMark = 0; string WaterImagePath = ""; int waterPosition = 0; string MediaLabel = ""; string MediaDescript = ""; string MediaTitle = ""; MediaClassId = int.Parse(context.Request["MediaClassId"].ToString()); MediaScale = context.Request["MediaScale"].ToString(); smallPiexl = int.Parse(context.Request["smallPiexl"].ToString()); WaterMark = int.Parse(context.Request["WaterMark"].ToString()); WaterImagePath = context.Request["WaterImagePath"].ToString(); waterPosition = int.Parse(context.Request["waterPosition"].ToString()); if (!string.IsNullOrEmpty(context.Request["MediaLabel"])) { MediaLabel = context.Request["MediaLabel"].ToString(); } if (!string.IsNullOrEmpty(context.Request["MediaLabel"])) { MediaLabel = context.Request["MediaLabel"].ToString(); } if (!string.IsNullOrEmpty(context.Request["MediaDescript"])) { MediaDescript = context.Request["MediaDescript"].ToString(); } if (!string.IsNullOrEmpty(context.Request["MediaTitle"])) { MediaTitle = context.Request["MediaTitle"].ToString(); } context.Response.ContentType = "text/plain"; HttpPostedFile file = context.Request.Files["Filedata"];//接受文件 string fileExt = file.FileName.Substring(file.FileName.LastIndexOf(".") + 1); if (!FileHelper.CheckFileExt(this.fileType, fileExt)) { context.Response.Write("不允许上传" + fileExt + "类型的文件"); } if (this.fileSize > 0 && file.ContentLength > fileSize * 1024) { context.Response.Write("文件超过限制的大小啦"); } MediaSize = file.ContentLength / 1024; filename = DateTime.Now.ToString("ddHHmmssfff") + Path.GetExtension(file.FileName); localPath = HttpContext.Current.Request.PhysicalApplicationPath + ("upimg/" + DateTime.Now.ToString("yyyyMM") + "/"); //判断文件夹是否存在, 不存在则创建 if (!System.IO.Directory.Exists(localPath)) { System.IO.Directory.CreateDirectory(localPath); } try { //本地创建上传的图片文件 file.SaveAs(Path.Combine(localPath, filename)); } catch (Exception) { strfile = "Error"; } string path = "/upimg/" + DateTime.Now.ToString("yyyyMM") + "/" + filename; byte[] Data = new byte[1]; Data = FileHelper.AddImageSignPic(File.ReadAllBytes(localPath + filename), path, WaterImagePath, waterPosition, waterQuality, waterTransparency, WaterMark); //读取本地图片, 转成二进制, 调用服务生成图片, 返回路径另上域名 if (FileServer.CreateFileImage(Data, path)) { strfile = "http://img.stock.com" + path; } else { strfile = "Error"; } //判断文件是否存在, 存在则删除 // if (File.Exists(localPath + filename)) // File.Delete(localPath + filename); Media Media = new Media(); MediaBLL MediaBLL = Factory.BusinessFactory.CreateBll <MediaBLL>(); if (!string.IsNullOrEmpty(path)) { Media.MediaClassId = MediaClassId; Media.MediaTitle = MediaTitle; Media.UploadTime = DateTime.Now; Media.UploadPath = path; Media.MediaSize = MediaSize; Media.MediaType = 1; Media.Uploader = UserCookies.AdminName; Media.MediaLabel = MediaLabel; Media.MediaDescript = MediaDescript; MediaBLL.Add(Media).ToString(); } context.Response.Write("/upimg/" + DateTime.Now.ToString("yyyyMM") + "/" + filename); }