Пример #1
0
        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;
                        }
                    }
                }
            }
        }