예제 #1
0
        protected string ServerMapFolder(string resourceType, string folderPath, bool isQuickUpload)
        {
            TypeConfig config = this.Config.TypeConfig[resourceType];
            string     path   = isQuickUpload ? config.GetQuickUploadDirectory() : config.GetFilesDirectory();

            Util.CreateDirectory(path);
            return(Path.Combine(path, folderPath.TrimStart(new char[] { '/' })));
        }
예제 #2
0
        public TypeConfig this[string typeName]
        {
            get
            {
                if ( !_Types.Contains( typeName ) )
                    _Types[ typeName ] = new TypeConfig( _FileWorker );

                return (TypeConfig)_Types[ typeName ];
            }
        }
예제 #3
0
        public TypeConfig this[string typeName]
        {
            get
            {
                if (!_Types.Contains(typeName))
                {
                    _Types[typeName] = new TypeConfig(_FileWorker);
                }

                return((TypeConfig)_Types[typeName]);
            }
        }
예제 #4
0
        protected string ServerMapFolder(string resourceType, string folderPath, bool isQuickUpload)
        {
            TypeConfig typeConfig = this.Config.TypeConfig[resourceType];

            // Get the resource type directory.
            string sResourceTypePath = isQuickUpload ? typeConfig.GetQuickUploadDirectory() : typeConfig.GetFilesDirectory();

            // Ensure that the directory exists.
            Util.CreateDirectory(sResourceTypePath);

            // Return the resource type directory combined with the required path.
            return(System.IO.Path.Combine(sResourceTypePath, folderPath.TrimStart('/')));
        }
예제 #5
0
        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);
        }
예제 #6
0
        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);
        }
예제 #7
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;
                        }
                    }
                }
            }
        }