/// <summary> /// 判断上传文件格式是否正确 /// </summary> /// <param name="UploadType">文件类型</param> /// <param name="FileExt">上传的文件扩展名</param> /// <returns></returns> protected bool FormatUploadType(string FileExt) { if (StringDeal.GetExtNameIsArry("asp,aspx,php,js,jsp".Split(','), FileExt)) { return(false); } else { string VideoType = GetConfig.File("VideoType"); string AudioType = GetConfig.File("AudioType"); string SoftType = GetConfig.File("SoftType"); string OtherType = GetConfig.File("OtherType"); //允许文件类型 if (UploadFileType == "VideoType") { return(StringDeal.GetExtNameIsArry(VideoType.Split(','), FileExt)); } else if (UploadFileType == "AudioType") { return(StringDeal.GetExtNameIsArry(AudioType.Split(','), FileExt)); } else if (UploadFileType == "SoftType") { return(StringDeal.GetExtNameIsArry(SoftType.Split(','), FileExt)); } else if (UploadFileType == "OtherType") { return(StringDeal.GetExtNameIsArry(OtherType.Split(','), FileExt)); } else { return(true); } } }
/// <summary> /// 上传 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnUpload_Click(object sender, EventArgs e) { try { foreach (Telerik.WebControls.UploadedFile file in RadUploadContext.Current.UploadedFiles) { if (file.FileName != "") { if (file.ContentLength > FileSize) { StringDeal.Alter("文件大小不能超过" + FileSize / 1024 + "KB"); } else if (StringDeal.GetExtNameIsArry(FileType.Split('|'), file.FileName)) { string FileExt = file.GetExtension(); System.Threading.Thread.Sleep(1000); string FileName = StringDeal.GetGuid() + FileExt; file.SaveAs(this.Server.MapPath(UploadPath + FileName), true); Response.StatusCode = 200; #region 生成缩略图 if (!String.IsNullOrEmpty(ThumbnailSize) && StringDeal.GetExtNameIsArry("gif|jpg|jpeg|png|bmp".Split(','), FileName)) { Thumbnail th = new Thumbnail(); th.FileName = FileName; th.OriginalImagePath = UploadPath; th.Width = StringDeal.ToInt(ThumbnailSize.Split('*')[0]); th.Height = StringDeal.ToInt(ThumbnailSize.Split('*')[1]); th.MakeThumbnail(); } #endregion this.uptd.Visible = false; this.but_close.Visible = false; this.but_over.Visible = true; this.btnUpload.Visible = false; Response.Write("<script language='javascript' type='text/javascript'>window.parent.$('" + InputName + "').value='" + FileName + "';window.parent.$('upid').innerHTML = '删除';</script>"); } } } } catch { } }
/// <summary> /// 提交后保存 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnUpload_Click(object sender, EventArgs e) { // mapFilePath = HttpContext.Current.Server.MapPath(filePath); string UploadImageName = ""; string UploadType = Request.Form["Upload"]; //图片方式 int ImageSize = StringDeal.ToInt(GetConfig.Image("ImageSize")); //图片最大上传 string UploadImagePath = GetConfig.Image("UploadImagePath"); //图片上传路径 string ImageType = GetConfig.Image("ImageType"); //允许图片类型 bool IsThumbnail = StringDeal.ToBool(Request.Form["IsThumbnail"]); //是否生成缩略图 int ThumbWidth = StringDeal.ToInt(Request.Form["ThumbWidth"]); //缩略图宽 int ThumbHeight = StringDeal.ToInt(Request.Form["ThumbHeight"]); //缩略图高 string ThumbMode = Request.Form["ThumbMode"]; bool IsWatermark = StringDeal.ToBool(Request.Form["IsWatermark"]); //加水印 string WatermarkImage = GetConfig.Image("WatermarkImage"); //水印图地址 int WatermarkPos = StringDeal.ToInt(GetConfig.Image("WatermarkPos")); //水印放置位置 string SelectImage = Request.Form["SelectImage"]; //选择服务器上的图片名 string WebUrl = Request.Form["WebUrl"]; //网络图片地址 if (String.IsNullOrEmpty(UploadImagePath)) { UploadImagePath = "../../Upload/image/"; } if (ImageSize == 0) { ImageSize = 1020000; } else { ImageSize = ImageSize * 1024; } if (String.IsNullOrEmpty(ImageType)) { ImageType = "jpg,gif,png,bmp,jpeg"; } if (UploadType == "upload1") { UploadImagePath = UploadImagePath + DateTime.Today.ToString("yyyyMM") + "/"; Files.CreateFolder(UploadImagePath); #region 大文件上传 try { foreach (Telerik.WebControls.UploadedFile file in RadUploadContext.Current.UploadedFiles) { System.Drawing.Image image = System.Drawing.Image.FromStream(file.InputStream); if (file.FileName != "") { if (file.ContentLength > ImageSize) { StringDeal.Alter("文件大小不能超过" + ImageSize / 1024 + "KB"); } else if (StringDeal.GetExtNameIsArry(ImageType.Split(','), file.FileName)) { string FileExt = file.GetExtension(); System.Threading.Thread.Sleep(1000); string FileName = StringDeal.GetGuid() + FileExt; file.SaveAs(this.Server.MapPath(UploadImagePath + FileName), true); Response.StatusCode = 200; #region 生成缩略图 if (IsThumbnail) { Thumbnail th = new Thumbnail(); th.Mode = ThumbMode; th.FileName = FileName; th.OriginalImagePath = UploadImagePath; th.Width = ThumbWidth; th.Height = ThumbHeight; th.MakeThumbnail(); } #endregion UploadImageName = UploadImagePath + FileName; } else { StringDeal.Alter("上传图片格式不正确!"); } } image.Dispose(); } } catch { } #endregion } else if (UploadType == "upload2") { #region 择服务器上的保存 if (IsThumbnail) { if (SelectImage != string.Empty) { if (!HXD.Common.Utils.IsUrl(SelectImage)) { if (HXD.Common.Utils.isPhotoIco(SelectImage)) { System.IO.File.Delete(Server.MapPath("~" + HXD.Common.Utils.PhotoIco(SelectImage))); } string FileName = string.Empty; FileName = SelectImage.Substring(SelectImage.LastIndexOf('/') + 1); UploadImagePath = SelectImage.Remove(SelectImage.LastIndexOf('/') + 1); Thumbnail th = new Thumbnail(); th.Mode = ThumbMode; th.FileName = FileName; th.OriginalImagePath = UploadImagePath; th.Width = ThumbWidth; th.Height = ThumbHeight; th.MakeThumbnail(); } } } UploadImageName = SelectImage; #endregion } else { #region 输入网络图片地址保存 UploadImageName = WebUrl; #endregion } Response.Write("<script language='javascript' type='text/javascript'>window.parent.loadinndlg().document.getElementById('" + InputName + "').value='" + UploadImageName + "';window.parent.cancel();</script>"); }