protected void FileUpload(string resourceType, string currentFolder, bool isQuickUpload) { string strWebDomain = "http://" + System.Web.HttpContext.Current.Request.ServerVariables["Http_Host"];//System.Web.HttpContext.Current.Request.ServerVariables["SERVER_NAME"]; HttpPostedFile oFile = Request.Files["NewFile"]; string sFileName = ""; if (oFile == null) { this.SendFileUploadResponse(202, isQuickUpload); return; } // Map the virtual path to the local server path. string sServerDir = this.ServerMapFolder(resourceType, currentFolder, isQuickUpload); // Get the uploaded file name. sFileName = System.IO.Path.GetFileName(oFile.FileName); sFileName = this.SanitizeFileName(sFileName); string sExtension = System.IO.Path.GetExtension(oFile.FileName); sExtension = sExtension.TrimStart('.'); sFileName = Guid.NewGuid() + "." + sExtension; if (!this.Config.TypeConfig[resourceType].CheckIsAllowedExtension(sExtension)) { this.SendFileUploadResponse(202, isQuickUpload); return; } if (this.Config.CheckIsNonHtmlExtension(sExtension) && !this.CheckNonHtmlFile(oFile)) { this.SendFileUploadResponse(202, isQuickUpload); return; } int iErrorNumber = 0; int iCounter = 0; while (true) { string sFilePath = System.IO.Path.Combine(sServerDir, sFileName); if (System.IO.File.Exists(sFilePath)) { iCounter++; /* * sFileName = * System.IO.Path.GetFileNameWithoutExtension( oFile.FileName ) + * "(" + iCounter + ")." + * sExtension; */ sFileName = Guid.NewGuid() + "." + sExtension; iErrorNumber = 201; } else { oFile.SaveAs(sFilePath); break; } } TypeConfig typeConfig = this.Config.TypeConfig[resourceType]; string sFileUrl = isQuickUpload ? typeConfig.GetQuickUploadPath() : typeConfig.GetFilesPath(); sFileUrl += sFileName; sFileUrl = strWebDomain + sFileUrl; this.SendFileUploadResponse(iErrorNumber, isQuickUpload, sFileUrl, sFileName); }
protected void FileUpload(string resourceType, string currentFolder, bool isQuickUpload) { HttpPostedFile oFile = Request.Files["NewFile"]; string sFileName = ""; if (oFile == null) { this.SendFileUploadResponse(202, isQuickUpload); return; } // Map the virtual path to the local server path. string sServerDir = this.ServerMapFolder(resourceType, currentFolder, isQuickUpload); // Get the uploaded file name. sFileName = System.IO.Path.GetFileName(oFile.FileName); sFileName = this.SanitizeFileName(sFileName); string sExtension = System.IO.Path.GetExtension(oFile.FileName); sExtension = sExtension.TrimStart('.'); if (!this.Config.TypeConfig[resourceType].CheckIsAllowedExtension(sExtension)) { this.SendFileUploadResponse(202, isQuickUpload); return; } if (this.Config.CheckIsNonHtmlExtension(sExtension) && !this.CheckNonHtmlFile(oFile)) { this.SendFileUploadResponse(202, isQuickUpload); return; } int iErrorNumber = 0; int iCounter = 0; while (true) { string sFilePath = System.IO.Path.Combine(sServerDir, sFileName); if (System.IO.File.Exists(sFilePath)) { iCounter++; sFileName = System.IO.Path.GetFileNameWithoutExtension(oFile.FileName) + "(" + iCounter + ")." + sExtension; iErrorNumber = 201; } else { oFile.SaveAs(Server.MapPath("~/app_pic/y_" + sFileName)); if (System.IO.File.Exists(Server.MapPath("~/App_Data/Water.png"))) { AddWaterPic(Server.MapPath("~/app_pic/y_" + sFileName), sFilePath, Server.MapPath("~/App_Data/Water.png")); } break; } } TypeConfig typeConfig = this.Config.TypeConfig[resourceType]; string sFileUrl = isQuickUpload ? typeConfig.GetQuickUploadPath() : typeConfig.GetFilesPath(); sFileUrl += sFileName; this.SendFileUploadResponse(iErrorNumber, isQuickUpload, sFileUrl, sFileName); }
protected void FileUpload(string resourceType, string currentFolder, bool isQuickUpload) { HttpPostedFile file = base.Request.Files["NewFile"]; string fileName = ""; if (file == null) { this.SendFileUploadResponse(0xca, isQuickUpload); } else { string str2 = this.ServerMapFolder(resourceType, currentFolder, isQuickUpload); fileName = Path.GetFileName(file.FileName); fileName = this.SanitizeFileName(fileName); string extension = Path.GetExtension(file.FileName).TrimStart(new char[] { '.' }); if (!this.Config.TypeConfig[resourceType].CheckIsAllowedExtension(extension)) { this.SendFileUploadResponse(0xca, isQuickUpload); } else if (!(!this.Config.CheckIsNonHtmlExtension(extension) || this.CheckNonHtmlFile(file))) { this.SendFileUploadResponse(0xca, isQuickUpload); } else { int errorNumber = 0; int num2 = 0; while (true) { string path = Path.Combine(str2, fileName); if (File.Exists(path)) { num2++; fileName = string.Concat(new object[] { Path.GetFileNameWithoutExtension(file.FileName), "(", num2, ").", extension }); errorNumber = 0xc9; } else { file.SaveAs(path); int waterType = ShopConfig.ReadConfigInfo().WaterType; int waterPossition = ShopConfig.ReadConfigInfo().WaterPossition; string text = ShopConfig.ReadConfigInfo().Text; string textFont = ShopConfig.ReadConfigInfo().TextFont; int textSize = ShopConfig.ReadConfigInfo().TextSize; string textColor = ShopConfig.ReadConfigInfo().TextColor; string waterImage = base.Server.MapPath(ShopConfig.ReadConfigInfo().WaterPhoto); switch (waterType) { case 2: case 3: { fileName = Path.GetFileNameWithoutExtension(file.FileName) + "_" + DateTime.Now.ToString("yyMMddhhmmss") + "." + extension; string newImage = Path.Combine(str2, fileName); if (waterType == 2) { ImageHelper.AddTextWater(path, newImage, waterPossition, text, textFont, textColor, textSize); } else { ImageHelper.AddImageWater(path, newImage, waterPossition, waterImage); } if (File.Exists(path)) { File.Delete(path); } break; } } TypeConfig config = this.Config.TypeConfig[resourceType]; string fileUrl = isQuickUpload ? config.GetQuickUploadPath() : config.GetFilesPath(); fileUrl = fileUrl + fileName; this.SendFileUploadResponse(errorNumber, isQuickUpload, fileUrl, fileName); return; } } } } }