protected void Page_Load(object sender, System.EventArgs e) { string a = Globals.RequestFormStr("posttype"); if (a == "togallery") { base.Response.ContentType = "application/json"; string s = "{\"type\":\"0\",\"tips\":\"操作失败\"}"; string text = Globals.RequestFormStr("photourl"); if (!string.IsNullOrEmpty(text)) { System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(base.Server.MapPath(text)); System.IO.MemoryStream memoryStream = new System.IO.MemoryStream(); bitmap.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Jpeg); GalleryHelper.AddPhote(0, "wb" + System.DateTime.Now.ToString("yyyyMMddHHmmss"), text, (int)memoryStream.Length); s = "{\"type\":\"1\",\"tips\":\"操作成功\"}"; memoryStream.Dispose(); } base.Response.Write(s); base.Response.End(); return; } this.btnImagetSearch.Click += new System.EventHandler(this.btnImagetSearch_Click); if (!base.IsPostBack) { this.LoadParameters(); this.BindImageData(); } }
protected void Page_Load(object sender, EventArgs e) { if (Globals.RequestFormStr("posttype") == "togallery") { base.Response.ContentType = "application/json"; string s = "{\"type\":\"0\",\"tips\":\"操作失败\"}"; string str3 = Globals.RequestFormStr("photourl"); if (!string.IsNullOrEmpty(str3)) { Bitmap bitmap = new Bitmap(base.Server.MapPath(str3)); MemoryStream stream = new MemoryStream(); bitmap.Save(stream, ImageFormat.Jpeg); GalleryHelper.AddPhote(0, "wb" + DateTime.Now.ToString("yyyyMMddHHmmss"), str3, (int)stream.Length); s = "{\"type\":\"1\",\"tips\":\"操作成功\"}"; stream.Dispose(); } base.Response.Write(s); base.Response.End(); } else { this.btnImagetSearch.Click += new EventHandler(this.btnImagetSearch_Click); if (!base.IsPostBack) { this.LoadParameters(); this.BindImageData(); } } }
private void btnSaveImageFtp_Click(object sender, EventArgs e) { string str = Globals.GetStoragePath() + "/gallery"; int categoryId = Convert.ToInt32(this.dropImageFtp.SelectedItem.Value); int num2 = 0; int num3 = 0; new StringBuilder(); HttpFileCollection files = base.Request.Files; for (int i = 0; i < files.Count; i++) { HttpPostedFile postedFile = files[i]; if (postedFile.ContentLength > 0) { num2++; try { string str2 = Guid.NewGuid().ToString("N", CultureInfo.InvariantCulture) + Path.GetExtension(postedFile.FileName); string str3 = postedFile.FileName.Substring(postedFile.FileName.LastIndexOf(@"\") + 1); string photoName = str3.Substring(0, str3.LastIndexOf(".")); string str5 = DateTime.Now.ToString("yyyyMM").Substring(0, 6); string virtualPath = str + "/" + str5 + "/"; int contentLength = postedFile.ContentLength; string path = base.Request.MapPath(virtualPath); string photoPath = "/Storage/master/gallery/" + str5 + "/" + str2; DirectoryInfo info = new DirectoryInfo(path); if (ResourcesHelper.CheckPostedFile(postedFile, "image")) { if (!info.Exists) { info.Create(); } postedFile.SaveAs(base.Request.MapPath(virtualPath + str2)); if (GalleryHelper.AddPhote(categoryId, photoName, photoPath, contentLength)) { num3++; } } } catch { } } } if (num2 == 0) { this.ShowMsg("至少需要选择一个图片文件!", false); } else { this.ShowMsg("成功上传了" + num3.ToString() + "个文件!", true); } }
private void btnSaveImageFtp_Click(object sender, System.EventArgs e) { string str = Globals.ApplicationPath + Hidistro.Membership.Context.HiContext.Current.GetStoragePath() + "/gallery"; int categoryId = System.Convert.ToInt32(this.dropImageFtp.SelectedItem.Value); int num = 0; int num2 = 0; new System.Text.StringBuilder(); System.Web.HttpFileCollection files = base.Request.Files; for (int i = 0; i < files.Count; i++) { System.Web.HttpPostedFile httpPostedFile = files[i]; if (httpPostedFile.ContentLength > 0) { num++; try { string text = System.Guid.NewGuid().ToString("N", System.Globalization.CultureInfo.InvariantCulture) + System.IO.Path.GetExtension(httpPostedFile.FileName); string text2 = httpPostedFile.FileName.Substring(httpPostedFile.FileName.LastIndexOf("\\") + 1); string photoName = text2.Substring(0, text2.LastIndexOf(".")); string text3 = System.DateTime.Now.ToString("yyyyMM").Substring(0, 6); string text4 = str + "/" + text3 + "/"; int contentLength = httpPostedFile.ContentLength; string path = base.Request.MapPath(text4); string photoPath = "/Storage/master/gallery/" + text3 + "/" + text; System.IO.DirectoryInfo directoryInfo = new System.IO.DirectoryInfo(path); if (ResourcesHelper.CheckPostedFile(httpPostedFile)) { if (!directoryInfo.Exists) { directoryInfo.Create(); } httpPostedFile.SaveAs(base.Request.MapPath(text4 + text)); if (GalleryHelper.AddPhote(categoryId, photoName, photoPath, contentLength)) { num2++; } } } catch { } } } if (num == 0) { this.ShowMsg("至少需要选择一个图片文件!", false); return; } this.ShowMsg("成功上传了" + num2.ToString() + "个文件!", true); }
private void UploadImage() { string value = this.hidUploadImages.Value; if (value.Trim().Length == 0) { this.ShowMsg("至少需要选择一个图片文件!", false); } else { int categoryId = Convert.ToInt32(this.dropImageFtp.SelectedItem.Value); int num = 0; string[] array = value.Split(','); for (int i = 0; i < array.Length; i++) { if (!string.IsNullOrEmpty(array[i])) { string text = array[i].Split('/')[4]; string text2 = DateTime.Now.ToString("yyyyMM").Substring(0, 6); string photoPath = "/Storage/master/gallery/" + text2 + "/" + text; string str = Globals.GetStoragePath() + "/temp/"; string text3 = HttpContext.Current.Server.MapPath(Globals.GetStoragePath() + "/gallery/" + text2 + "/"); if (!Globals.PathExist(text3, false)) { Globals.CreatePath(text3); } if (!File.Exists(text3 + text)) { File.Copy(HttpContext.Current.Server.MapPath(array[i]), text3 + text); FileInfo fileInfo = new FileInfo(text3 + text); int fileSize = 0; int.TryParse(fileInfo.Length.ToString(), out fileSize); if (GalleryHelper.AddPhote(categoryId, text, photoPath, fileSize, 0)) { num++; } string path = HttpContext.Current.Server.MapPath(str + text); if (File.Exists(path)) { File.Delete(path); } continue; } return; } } base.CloseWindow(null); this.ShowMsg("成功上传了" + num.ToString() + "个文件!", true); } }
public override void Process() { byte[] buffer = null; string filename = null; int fileSize = 0; if (this.UploadConfig.Base64) { filename = this.UploadConfig.Base64Filename; buffer = Convert.FromBase64String(base.Request[this.UploadConfig.UploadFieldName]); } else { HttpPostedFile file = base.Request.Files[this.UploadConfig.UploadFieldName]; filename = file.FileName; if (!this.CheckFileType(filename)) { this.Result.State = UploadState.TypeNotAllow; this.WriteResult(); return; } if (!this.CheckFileSize(file.ContentLength)) { this.Result.State = UploadState.SizeLimitExceed; this.WriteResult(); return; } fileSize = file.ContentLength; buffer = new byte[file.ContentLength]; try { file.InputStream.Read(buffer, 0, file.ContentLength); } catch (Exception) { this.Result.State = UploadState.NetworkError; this.WriteResult(); } } this.Result.OriginFileName = filename; string path = PathFormatter.Format(filename, this.UploadConfig.PathFormat); string str3 = base.Server.MapPath(path); try { if (!Directory.Exists(Path.GetDirectoryName(str3))) { Directory.CreateDirectory(Path.GetDirectoryName(str3)); } GalleryHelper.AddPhote(Globals.RequestFormNum("cate_id"), this.Result.OriginFileName, path, fileSize); File.WriteAllBytes(str3, buffer); this.Result.Url = path; this.Result.State = UploadState.Success; } catch (Exception exception) { this.Result.State = UploadState.FileAccessError; this.Result.ErrorMessage = exception.Message; } finally { this.WriteResult(); } }
public override void Process() { byte[] array = null; string text = null; int fileSize = 0; if (this.UploadConfig.Base64) { text = this.UploadConfig.Base64Filename; array = Convert.FromBase64String(base.Request[this.UploadConfig.UploadFieldName]); } else { HttpPostedFile httpPostedFile = base.Request.Files[this.UploadConfig.UploadFieldName]; text = httpPostedFile.FileName; if (!this.CheckFileType(text)) { this.Result.State = UploadState.TypeNotAllow; this.WriteResult(); return; } if (!this.CheckFileSize(httpPostedFile.ContentLength)) { this.Result.State = UploadState.SizeLimitExceed; this.WriteResult(); return; } fileSize = httpPostedFile.ContentLength; array = new byte[httpPostedFile.ContentLength]; try { httpPostedFile.InputStream.Read(array, 0, httpPostedFile.ContentLength); } catch (Exception) { this.Result.State = UploadState.NetworkError; this.WriteResult(); } } this.Result.OriginFileName = text; string text2 = PathFormatter.Format(text, this.UploadConfig.PathFormat); string path = base.Server.MapPath(text2); try { if (!Directory.Exists(Path.GetDirectoryName(path))) { Directory.CreateDirectory(Path.GetDirectoryName(path)); } GalleryHelper.AddPhote(Convert.ToInt32(base.Request.Form["cate_id"]), this.Result.OriginFileName, text2, fileSize, 0); File.WriteAllBytes(path, array); this.Result.Url = text2; this.Result.State = UploadState.Success; } catch (Exception ex2) { this.Result.State = UploadState.FileAccessError; this.Result.ErrorMessage = ex2.Message; } finally { this.WriteResult(); } }