public void GetProductPic(ProductInfo productInfo) { productInfo.ProductPic = this.FileUploadProductPic.FilePath; string oldValue = base.BasePath + SiteConfig.SiteOption.UploadDir; string originalImagePath = productInfo.ProductPic.Replace(oldValue, ""); if (this.ChkThumb.Checked) { if (!string.IsNullOrEmpty(productInfo.ProductPic)) { try { string extension = Path.GetExtension(productInfo.ProductPic); string str4 = productInfo.ProductPic.Replace(extension, "_S" + extension); productInfo.ProductThumb = Thumbs.GetThumbsPath(originalImagePath, str4.Replace(oldValue, "")); } catch (ArgumentException) { BaseUserControl.WriteErrMsg("<li>生成缩略图的路径中具有非法字符!</li>"); } } } else { productInfo.ProductThumb = this.FileUploadProductThumb.FilePath; } if (this.ChkProductPicWatermark.Checked && !string.IsNullOrEmpty(productInfo.ProductPic)) { WaterMark.AddWaterMark(originalImagePath); } if (((this.ChkProductPicWatermark.Checked && this.ChkThumb.Checked) || this.ChkProductThumbWatermark.Checked) && !string.IsNullOrEmpty(productInfo.ProductThumb)) { WaterMark.AddWaterMark(productInfo.ProductThumb.Replace(oldValue, "")); } }
protected void WaterMarkByFile(string filePath, string fileName, string extension) { string str = this.m_CurrentDir + "/" + filePath + "/"; if (this.IsPhoto(extension)) { WaterMark.AddWaterMark(str + fileName); } }
public IActionResult ThumbsConfig() { var thumbsConfig = ConfigHelper.Get <ThumbsConfig>(); string strMsg = "AddBackColor:" + thumbsConfig.AddBackColor + " "; strMsg += "ThumbsMode:" + thumbsConfig.ThumbsMode + " "; strMsg += "ThumbsWidth:" + thumbsConfig.ThumbsWidth + " "; strMsg += "ThumbsHeight:" + thumbsConfig.ThumbsHeight + " "; strMsg += "静态文件目录路径:" + FileHelper.WebRootPath + " "; strMsg += "静态文件目录名称:" + FileHelper.WebRootName + " "; ViewData["Msg"] = strMsg; var thumbUrl = Thumbs.GetThumbUrl(Utility.GetBasePath() + Utility.UploadDirPath() + "test.jpg", true); ViewData["ImageUrl"] = Url.Content(thumbUrl); var thumbPath = Thumbs.GetThumbPath(Utility.UploadDirPath(true) + "test1.jpg", true); ViewData["ImagePath"] = Url.Content(thumbPath); var waterMarkConfig = ConfigHelper.Get <WaterMarkConfig>(); string strWaterMarkMsg = "WaterMarkType:" + waterMarkConfig.WaterMarkType + " "; strWaterMarkMsg += "FoneBorder:" + waterMarkConfig.WaterMarkTextInfo.FoneBorder + " "; strWaterMarkMsg += "FoneBorderColor:" + waterMarkConfig.WaterMarkTextInfo.FoneBorderColor + " "; strWaterMarkMsg += "FoneColor:" + waterMarkConfig.WaterMarkTextInfo.FoneColor + " "; strWaterMarkMsg += "FoneSize:" + waterMarkConfig.WaterMarkTextInfo.FoneSize + " "; strWaterMarkMsg += "FoneStyle:" + waterMarkConfig.WaterMarkTextInfo.FoneStyle + " "; strWaterMarkMsg += "FoneType:" + waterMarkConfig.WaterMarkTextInfo.FoneType + " "; strWaterMarkMsg += "Text:" + waterMarkConfig.WaterMarkTextInfo.Text + " "; strWaterMarkMsg += "WaterMarkPosition:" + waterMarkConfig.WaterMarkTextInfo.WaterMarkPosition + " "; strWaterMarkMsg += "WaterMarkPositionX:" + waterMarkConfig.WaterMarkTextInfo.WaterMarkPositionX + " "; strWaterMarkMsg += "WaterMarkPositionY:" + waterMarkConfig.WaterMarkTextInfo.WaterMarkPositionY + " "; strWaterMarkMsg += "ImagePath:" + waterMarkConfig.WaterMarkImageInfo.ImagePath + " "; strWaterMarkMsg += "Transparence:" + waterMarkConfig.WaterMarkImageInfo.Transparence + " "; strWaterMarkMsg += "WaterMarkPercent:" + waterMarkConfig.WaterMarkImageInfo.WaterMarkPercent + " "; strWaterMarkMsg += "WaterMarkPercentType:" + waterMarkConfig.WaterMarkImageInfo.WaterMarkPercentType + " "; strWaterMarkMsg += "WaterMarkPosition:" + waterMarkConfig.WaterMarkImageInfo.WaterMarkPosition + " "; strWaterMarkMsg += "WaterMarkPositionX:" + waterMarkConfig.WaterMarkImageInfo.WaterMarkPositionX + " "; strWaterMarkMsg += "WaterMarkPositionY:" + waterMarkConfig.WaterMarkImageInfo.WaterMarkPositionY + " "; strWaterMarkMsg += "WaterMarkThumbPercent:" + waterMarkConfig.WaterMarkImageInfo.WaterMarkThumbPercent + " "; ViewData["WaterMarkMsg"] = strWaterMarkMsg; WaterMark.AddWaterMark(FileHelper.WebRootName + FileHelper.DirectorySeparatorChar + Utility.UploadDirPath() + "test.jpg"); ViewData["WaterUrl"] = Url.Content(Utility.GetBasePath() + Utility.UploadDirPath() + "test.jpg"); waterMarkConfig.WaterMarkType = 0; waterMarkConfig.WaterMarkTextInfo.Text = "asp.net core"; ConfigHelper.Save(waterMarkConfig); return(View()); }
/// <summary> /// 文件上传方法 /// </summary> /// <param name="postedFile">文件类型</param> /// <param name="isThumbnail">是否缩略图</param> /// <param name="isWater">是否增加水印</param> /// <returns></returns> public UploadFileInfo UploadFile(IFormFile fileinput, bool isThumbnail = false, bool isWater = false) { var filepath = ContentDispositionHeaderValue.Parse(fileinput.ContentDisposition).FileName.Trim('"'); long fileSize = 0; //string fileExt = filepath.Substring(filepath.LastIndexOf('.')).Replace("\"", ""); string fileExt = fileinput.FileName.Substring(fileinput.FileName.LastIndexOf('.') + 1, fileinput.FileName.Length - fileinput.FileName.LastIndexOf('.') - 1); //string fileExt = fileinput.FileName.Substring(filepath.LastIndexOf('.')).Replace("\"", ""); string fileName = filepath.Substring(filepath.LastIndexOf(@"\", System.StringComparison.Ordinal) + 1); //取得原文件名 //string fileExt =FileHelper.GetFileExt(postedFile.FileName); //文件扩展名,不含“.” //int fileSize = postedFile.ContentLength; //获得文件大小,以字节为单位 //string fileName = postedFile.FileName.Substring(postedFile.FileName.LastIndexOf(@"\", System.StringComparison.Ordinal) + 1); //取得原文件名 string newFileName = Utils.GetCheckCode(20).ToLower() + "." + fileExt; //随机生成新的文件名 string newThumbnailFileName = "thumb_" + newFileName; //随机生成缩略图文件名 string upLoadPath = AssigendPath(fileExt, _sysconfig.filerootpath + "/" + _sysconfig.filepath); //上传目录相对路径 string fullUpLoadPath = Utils.GetMapPath(upLoadPath); //上传目录的物理路径 string newFilePath = upLoadPath + newFileName; //上传后的路径 string newThumbnailPath = upLoadPath + newThumbnailFileName; //上传后的缩略图路径 fileSize += fileinput.Length; //检查上传的物理路径是否存在,不存在则创建 if (!Directory.Exists(fullUpLoadPath)) { Directory.CreateDirectory(fullUpLoadPath); } using (FileStream fs = System.IO.File.Create(fullUpLoadPath + newFileName)) { fileinput.CopyTo(fs); fs.Flush(); } //保存文件 //postedFile.SaveAs(fullUpLoadPath + newFileName); //如果是图片,检查图片是否超出最大尺寸,是则裁剪 if (IsImage(fileExt) && (this._sysconfig.imgmaxheight > 0 || this._sysconfig.imgmaxwidth > 0)) { Thumbnail.MakeThumbnailImage(fullUpLoadPath + newFileName, fullUpLoadPath + newFileName, this._sysconfig.imgmaxwidth, this._sysconfig.imgmaxheight); } //如果是图片,检查是否需要生成缩略图,是则生成 if (IsImage(fileExt) && isThumbnail && this._sysconfig.thumbnailwidth > 0 && this._sysconfig.thumbnailheight > 0) { Thumbnail.MakeThumbnailImage(fullUpLoadPath + newFileName, fullUpLoadPath + newThumbnailFileName, this._sysconfig.thumbnailwidth, this._sysconfig.thumbnailheight, "H"); } //如果是图片,检查是否需要打水印 if (IsWaterMark(fileExt) && isWater) { switch (this._sysconfig.watermarktype) { case 1: //WaterMark.AddImageSignText(newFilePath, newFilePath, // this._sysconfig.watermarktext, this._sysconfig.watermarkposition, // this._sysconfig.watermarkimgquality, this._sysconfig.watermarkfont, this._sysconfig.watermarkfontsize); WaterMark.AddWaterMark(newFilePath, newFilePath, this._sysconfig.watermarktext, this._sysconfig.watermarkposition, this._sysconfig.watermarkimgquality, this._sysconfig.watermarkfont, this._sysconfig.watermarkfontsize); break; case 2: var watermarkpic = this._sysconfig.watermarkpic; if (!watermarkpic.Contains("wwwroot")) { watermarkpic = "/wwwroot" + watermarkpic; } WaterMark.AddImageSignPic(newFilePath, newFilePath, watermarkpic, this._sysconfig.watermarkposition, this._sysconfig.watermarkimgquality, this._sysconfig.watermarktransparency); break; } } var m = new UploadFileInfo() { OriginalName = filepath, Size = FileSizeTransf(fileSize), FileName = newFilePath, Name = newFileName, ThumbFileName = newThumbnailPath, ThumbName = newThumbnailFileName, FileExt = "." + fileExt, Paths = newFilePath }; return(m); }
protected void BtnUpload_Click(object sender, EventArgs e) { if (!SiteConfig.SiteOption.EnableUploadFiles) { this.LblMessage.Text = "权限错误:你当前的网站没有开启上传功能,请检查你的网站配置。"; } else { string str = BasePage.RequestString("ReturnJSFunction"); int num = DataConverter.CLng(base.Request.Form["ThumbIndex"]); if (string.IsNullOrEmpty(str)) { str = "DealwithUpload"; } StringBuilder builder = new StringBuilder(); builder.Append("<script language=\"javascript\" type=\"text/javascript\">"); int num2 = 0; StringBuilder builder2 = new StringBuilder(); if (!PEContext.Current.Admin.Identity.IsAuthenticated) { int uploadSize = PEContext.Current.User.UserInfo.UserPurview.UploadSize; if (this.m_PhotoSize > uploadSize) { this.m_PhotoSize = uploadSize; } } for (int i = 0; i < 10; i++) { num2++; System.Web.UI.WebControls.FileUpload upload = (System.Web.UI.WebControls.FileUpload) this.FindControl("FileUpload" + i.ToString()); if (upload.HasFile) { string str2 = Path.GetExtension(upload.FileName).ToLower(); if (!this.CheckFilePostfix(str2.Replace(".", ""))) { builder2.Append("文件" + upload.FileName + "上传文件类型不对!必须上传" + this.m_FileExtArr + @"的后缀名!\n"); } else if (((int)upload.FileContent.Length) > (this.m_PhotoSize * 0x400)) { builder2.Append("文件" + upload.FileName + "请上传小于" + this.m_PhotoSize.ToString() + @"KB的文件!\n"); } else { string str3 = DataSecurity.MakeFileRndName() + i.ToString(); string filename = FileSystemObject.CreateFileFolder((VirtualPathUtility.AppendTrailingSlash(SiteConfig.SiteOption.UploadDir) + this.FileSavePath(upload.FileName)).Replace("//", "/"), HttpContext.Current) + str3 + str2; upload.SaveAs(filename); Thumbs.GetThumbsPath(this.m_ShowPath + str3 + str2, this.m_ShowPath + str3 + "_S" + str2); if (this.m_Watermark) { WaterMark.AddWaterMark(this.m_ShowPath + str3 + str2); } EasyOne.Model.Accessories.FileInfo fileInfo = new EasyOne.Model.Accessories.FileInfo(); fileInfo.Name = upload.FileName; fileInfo.Path = this.m_ShowPath + str3 + str2; fileInfo.Size = (int)upload.FileContent.Length; fileInfo.Quote = 1; Files.Add(fileInfo); if (i == num) { builder.Append("parent." + str + "ChangeThumbField(\"" + fileInfo.Path + "\",\"" + this.m_ShowPath + str3 + "_S" + str2 + "\");"); } else { builder.Append("parent." + str + "DealwithUpload(\"" + fileInfo.Path + "\",\"" + fileInfo.Size.ToString() + "\",\"" + fileInfo.Id.ToString() + "\",\"" + this.m_ShowPath + str3 + "_S" + str2 + "\");"); } builder2.Append("文件" + upload.FileName + @"上传成功!\n"); } } } if (builder2.Length > 0) { builder.Append("parent." + str + "ErrMessage(\"" + builder2.ToString() + "\");"); } builder.Append("</script>"); this.Page.ClientScript.RegisterStartupScript(base.GetType(), "UpdateParent", builder.ToString()); } }
protected void BtnUpload_Click(object sender, EventArgs e) { if (!this.FupFile.HasFile) { this.ReturnManage("上传失败,重新上传。"); return; } int uploadFileMaxSize = 0; int uploadSize = 0; bool flag = false; bool flag2 = false; if (!SiteConfig.SiteOption.EnableUploadFiles) { this.ReturnManage("权限错误:对不起网站没有开启上传权限。"); return; } if (!PEContext.Current.Admin.Identity.IsAuthenticated) { if (!PEContext.Current.User.Identity.IsAuthenticated) { UserGroupsInfo userGroupById = UserGroups.GetUserGroupById(-2); if (string.IsNullOrEmpty(userGroupById.GroupSetting)) { this.ReturnManage("匿名会员组不存在!"); return; } UserPurviewInfo groupSetting = UserGroups.GetGroupSetting(userGroupById.GroupSetting); if (groupSetting.IsNull) { this.ReturnManage("匿名会员组没有进行权限设置!"); return; } if (!groupSetting.EnableUpload) { this.ReturnManage("匿名会员组没有开启上传权限!"); return; } uploadSize = groupSetting.UploadSize; } else { if (!PEContext.Current.User.UserInfo.UserPurview.EnableUpload) { this.ReturnManage("所属会员组没有开启上传权限!"); return; } uploadSize = PEContext.Current.User.UserInfo.UserPurview.UploadSize; } } string str = Path.GetExtension(this.FupFile.FileName).ToLower(); if (!this.CheckFilePostfix(str.Replace(".", ""))) { this.ReturnManage("上传文件类型不对!必须上传" + this.m_FileExtArr + "的后缀名!"); return; } if (string.Compare(this.m_ModuleName, "Node", StringComparison.OrdinalIgnoreCase) == 0) { FieldInfo fieldInfoByFieldName = Field.GetFieldInfoByFieldName(this.m_ModelId, this.m_FieldName); Collection <string> settings = fieldInfoByFieldName.Settings; switch (fieldInfoByFieldName.FieldType) { case FieldType.PictureType: uploadFileMaxSize = DataConverter.CLng(settings[1]); flag2 = DataConverter.CBoolean(settings[4]); flag = DataConverter.CBoolean(settings[5]); goto Label_01EA; case FieldType.FileType: uploadFileMaxSize = DataConverter.CLng(settings[0]); goto Label_01EA; } } else { uploadFileMaxSize = SiteConfig.SiteOption.UploadFileMaxSize; } Label_01EA: if (!PEContext.Current.Admin.Identity.IsAuthenticated && (uploadFileMaxSize > uploadSize)) { uploadFileMaxSize = uploadSize; } if (((int)this.FupFile.FileContent.Length) > (uploadFileMaxSize * 0x400)) { this.ReturnManage("请上传小于" + uploadFileMaxSize.ToString() + "KB的文件!"); } else { string str2 = DataSecurity.MakeFileRndName(); string filename = FileSystemObject.CreateFileFolder((VirtualPathUtility.AppendTrailingSlash(SiteConfig.SiteOption.UploadDir) + this.FileSavePath()).Replace("//", "/"), HttpContext.Current) + str2 + str; this.FupFile.SaveAs(filename); string thumbnailPath = ""; if (flag) { thumbnailPath = this.m_ShowPath + str2 + "_S" + str; Thumbs.GetThumbsPath(this.m_ShowPath + str2 + str, thumbnailPath); } else { thumbnailPath = this.m_ShowPath + str2 + str; } if (flag2) { WaterMark.AddWaterMark(this.m_ShowPath + str2 + str); } EasyOne.Model.Accessories.FileInfo fileInfo = new EasyOne.Model.Accessories.FileInfo(); fileInfo.Name = this.FupFile.FileName; fileInfo.Path = thumbnailPath; fileInfo.Size = (int)this.FupFile.FileContent.Length; fileInfo.Quote = 1; if (string.Compare(this.m_ModuleName, "soft", StringComparison.OrdinalIgnoreCase) == 0) { Files.Add(fileInfo); } this.GetScriptByModuleName(fileInfo); this.ReturnManage("上传成功!"); } }
protected override void OnLoad(EventArgs e) { HttpPostedFile file = base.Request.Files["NewFile"]; string str = Path.GetExtension(file.FileName).ToLower(); string uploaderType = base.Request.Form["UploaderType"]; bool flag = DataConverter.CBoolean(base.Request.Form["IsWatermark"]); bool flag2 = DataConverter.CBoolean(base.Request.Form["IsThumb"]); int modelId = DataConverter.CLng(base.Request.Form["ModelId"]); string str3 = DataSecurity.FilterBadChar(base.Request.Form["FieldName"]); string allowSuffix = ""; int uploadFileMaxSize = 0; int uploadSize = 0; string customMsg = "请检查网站信息配置是否设置允许的上传文件大小!"; if (!SiteConfig.SiteOption.EnableUploadFiles) { this.SendResults(0xcc); } else { if (!PEContext.Current.Admin.Identity.IsAuthenticated) { if (!PEContext.Current.User.Identity.IsAuthenticated) { UserGroupsInfo userGroupById = UserGroups.GetUserGroupById(-2); if (string.IsNullOrEmpty(userGroupById.GroupSetting)) { this.SendResults(1, "", "", "匿名会员组不存在!"); return; } UserPurviewInfo groupSetting = UserGroups.GetGroupSetting(userGroupById.GroupSetting); if (groupSetting.IsNull) { this.SendResults(1, "", "", "匿名会员组没有进行权限设置!"); return; } if (!groupSetting.EnableUpload) { this.SendResults(1, "", "", "匿名会员组没有开启上传权限!"); return; } uploadSize = groupSetting.UploadSize; } else { if (!PEContext.Current.User.UserInfo.UserPurview.EnableUpload) { this.SendResults(1, "", "", "所属会员组没有开启上传权限!"); return; } uploadSize = PEContext.Current.User.UserInfo.UserPurview.UploadSize; } } if ((file == null) || (file.ContentLength == 0)) { this.SendResults(0xca); } else { if ((modelId == 0) || string.IsNullOrEmpty(str3)) { if (!ConfigurationManager.AppSettings["EasyOne:DefaultUploadSuffix"].ToLower().Contains(str)) { this.SendResults(1, "", "", "不允许上传动态页文件!"); return; } uploadFileMaxSize = SiteConfig.SiteOption.UploadFileMaxSize; } else { IList <FieldInfo> fieldListByModelId = ModelManager.GetFieldListByModelId(modelId); if ((fieldListByModelId != null) && (fieldListByModelId.Count > 0)) { foreach (FieldInfo info3 in fieldListByModelId) { if (string.CompareOrdinal(info3.FieldName, str3) == 0) { allowSuffix = GetAllowSuffix(info3, uploaderType); if (info3.Settings.Count > 7) { uploadFileMaxSize = DataConverter.CLng(info3.Settings[7]); } break; } } } if (string.IsNullOrEmpty(allowSuffix)) { this.SendResults(1, "", "", "字段内容控件没有填写允许上传的后缀!"); return; } if (!allowSuffix.Contains(str.Replace(".", ""))) { this.SendResults(1, "", "", "这种文件类型不允许上传!只允许上传这几种文件类型:" + allowSuffix); return; } customMsg = "请检查所属字段控件是否设置了允许上传文件大小!"; } if (uploadFileMaxSize <= 0) { this.SendResults(1, "", "", customMsg); } else { if (!PEContext.Current.Admin.Identity.IsAuthenticated && (uploadFileMaxSize > uploadSize)) { uploadFileMaxSize = uploadSize; } if (file.ContentLength > (uploadFileMaxSize * 0x400)) { this.SendResults(1, "", "", "请上传小于" + uploadFileMaxSize.ToString() + "KB的文件!"); } else { string str9; int errorNumber = 0; string fileUrl = ""; string str7 = DataSecurity.MakeFileRndName(); string str8 = str7 + str; int num5 = 0; while (true) { str9 = Path.Combine(base.UserFilesDirectory, str8); if (!File.Exists(str9)) { break; } num5++; str8 = string.Concat(new object[] { Path.GetFileNameWithoutExtension(file.FileName), "(", num5, ")", Path.GetExtension(file.FileName) }); errorNumber = 0xc9; } file.SaveAs(str9); fileUrl = base.UserFilesPath + str8; if (!string.IsNullOrEmpty(uploaderType) && (string.CompareOrdinal(uploaderType, "Photo") == 0)) { string oldValue = ""; if (base.Request.ApplicationPath.EndsWith("/", StringComparison.Ordinal)) { oldValue = ("/" + SiteConfig.SiteOption.UploadDir + "/").Replace("//", "/"); } else { oldValue = base.Request.ApplicationPath + "/" + SiteConfig.SiteOption.UploadDir; } if (flag2) { string str11 = base.UserFilesPath + str7 + "_S" + str; Thumbs.GetThumbsPath(fileUrl.Replace(oldValue, ""), str11.Replace(oldValue, "")); } if (flag) { WaterMark.AddWaterMark(fileUrl.Replace(oldValue, "")); } } this.SendResults(errorNumber, fileUrl, str8); } } } } }