Ejemplo n.º 1
0
        private bool IsRewriter(string url)
        {
            if (url.IndexOf('?') > -1)
            {
                url = url.Split(new char[] { '?' })[0];
            }
            //string str = FileHelper.GetFolderName(url).ToLower();
            string str   = url.ToLower();
            string str2  = FileHelper.GetFileExtension(url).ToLower();
            bool   flag  = false;
            bool   flag2 = true;
            string str3  = forbidFolder.ToLower();

            if (str3.Length > 1)
            {
                str3 = str3.Substring(1, str3.Length - 2);
            }
            foreach (string str4 in str3.Split(new char[] { '|' }))
            {
                if (str.IndexOf(str4) == 0)
                {
                    flag2 = false;
                    break;
                }
            }
            if ((str2 == string.Empty || (fileType.ToLower().IndexOf("|" + str2 + "|") > -1)) && flag2)
            {
                flag = true;
            }
            return(flag);
        }
Ejemplo n.º 2
0
        public FileInfo SaveAs()
        {
            HttpFileCollection files = HttpContext.Current.Request.Files;
            FileInfo           info  = null;

            try
            {
                for (int i = 0; i < files.Count; i++)
                {
                    this.postedFile    = files[i];
                    this.localFilePath = this.postedFile.FileName;
                    if ((this.localFilePath == null) || (this.localFilePath == ""))
                    {
                        throw new Exception("不能上传空文件");
                    }
                    this.localFileLength = this.postedFile.ContentLength;
                    if (this.localFileLength >= (this.sizes * 0x400))
                    {
                        throw new Exception("上传的文件不能大于:" + this.sizes + "KB");
                    }
                    this.saveFileFolderPath = this.GetSaveFileFolderPath();
                    this.localFileName      = System.IO.Path.GetFileName(this.postedFile.FileName);
                    this.fileExtension      = FileHelper.GetFileExtension(this.localFileName);
                    if (this.fileType.ToLower().IndexOf(this.fileExtension.ToLower()) == -1)
                    {
                        throw new Exception("目前本系统支持的格式为:" + this.fileType);
                    }
                    this.saveFileName     = FileHelper.CreateFileName(this.fileNameType, this.localFileName, this.fileExtension);
                    this.saveFileFullPath = this.saveFileFolderPath + this.saveFileName;
                    this.postedFile.SaveAs(this.saveFileFullPath);


                    if (allImageIsNail == 1)                                                                                                                                                                   //如果网站设置开启压缩图片
                    {
                        if (this.fileExtension == ".jpg" || this.fileType.ToLower() == ".jpeg" || this.fileType.ToLower() == ".gif" || this.fileType.ToLower() == ".png" || this.fileType.ToLower() == ".bmp") //如果后缀名为图片格式则进行压缩
                        {
                            Image image = Image.FromFile(this.saveFileFullPath);
                            if (image.Width > maxWidth)//如果图片超出设置的编辑器图片宽度,将图片压缩
                            {
                                string filePath = this.saveFileFolderPath + this.saveFileName;
                                string nailPath = this.saveFileFolderPath + "temp_nail" + this.fileExtension;
                                ImageHelper.MakeThumbnailImage(this.saveFileFullPath, nailPath, maxWidth, maxWidth, ThumbnailType.WidthFix);
                                image.Dispose();
                                System.IO.File.Delete(filePath);         //删除原图
                                System.IO.File.Move(nailPath, filePath); //重命名压缩后的文件
                            }
                            image.Dispose();
                        }
                    }

                    info = new FileInfo(this.saveFileFolderPath + this.saveFileName);
                }
            }
            catch
            {
                throw;
            }
            return(info);
        }
Ejemplo n.º 3
0
        public FileInfo SaveFromTaobao(string fileName)
        {
            this.saveFileFolderPath = ServerHelper.MapPath("~/Upload/TaoBaoPhoto/Original/");
            FileInfo info = new FileInfo(ServerHelper.MapPath(fileName));

            try
            {
                if (fileName == "")
                {
                    throw new Exception("不能上传空文件");
                }
                this.localFileLength = info.Length;
                if (this.localFileLength >= (this.sizes * 0x400))
                {
                    throw new Exception("上传的图片不能大于:" + this.sizes + "KB");
                }
                this.fileExtension = FileHelper.GetFileExtension(fileName);
                if (this.fileType.ToLower().IndexOf(this.fileExtension) == -1)
                {
                    throw new Exception("目前本系统支持的格式为:" + this.fileType);
                }

                this.saveFileFullPath = ServerHelper.MapPath(fileName);

                if (this.allImageIsNail == 1)                                                                                                                                                              //如果网站设置开启压缩图片
                {
                    if (this.fileExtension == ".jpg" || this.fileType.ToLower() == ".jpeg" || this.fileType.ToLower() == ".gif" || this.fileType.ToLower() == ".png" || this.fileType.ToLower() == ".bmp") //如果后缀名为图片格式则进行压缩
                    {
                        Image image = Image.FromFile(this.saveFileFullPath);
                        if (image.Width > maxWidth)//如果图片超出设置的编辑器图片宽度,将图片压缩
                        {
                            string filePath = this.saveFileFullPath;
                            string nailPath = this.saveFileFolderPath + "temp_nail" + this.fileExtension;
                            ImageHelper.MakeThumbnailImage(this.saveFileFullPath, nailPath, maxWidth, maxWidth, ThumbnailType.WidthFix);
                            image.Dispose();
                            System.IO.File.Delete(filePath);         //删除原图
                            System.IO.File.Move(nailPath, filePath); //重命名压缩后的文件
                        }
                        image.Dispose();
                    }
                }
                info = new FileInfo(saveFileFullPath);
            }
            catch
            {
                throw;
            }
            return(info);
        }
Ejemplo n.º 4
0
        public FileInfo SaveFromTaobao(int waterType, int waterPossition, string text, string textFont, int textSize, string textColor, string waterPhoto, string fileName)
        {
            this.saveFileFolderPath = ServerHelper.MapPath("~/Upload/TaoBaoPhoto/Original/");
            FileInfo info = new FileInfo(ServerHelper.MapPath(fileName));

            try
            {
                if (fileName == "")
                {
                    throw new Exception("不能上传空文件");
                }
                this.localFileLength = info.Length;
                if (this.localFileLength >= (this.sizes * 0x400))
                {
                    throw new Exception("上传的图片不能大于:" + this.sizes + "KB");
                }
                this.fileExtension = FileHelper.GetFileExtension(fileName);
                if (this.fileType.ToLower().IndexOf(this.fileExtension) == -1)
                {
                    throw new Exception("目前本系统支持的格式为:" + this.fileType);
                }

                this.saveFileFullPath = ServerHelper.MapPath(fileName);

                var imgTypes = ".jpg|.gif|.bmp|.png|.jpeg";
                if (imgTypes.IndexOf(this.fileExtension.ToLower()) != -1) //必须是图片类型才能加压缩
                {
                    if (allImageIsNail == 1)                              //如果网站设置开启压缩图片
                    {
                        Image image = Image.FromFile(this.saveFileFullPath);
                        if (image.Width > maxWidth)//如果图片超出设置的编辑器图片宽度,将图片压缩
                        {
                            string filePath = this.saveFileFullPath;
                            string nailPath = this.saveFileFolderPath + "temp_nail" + this.fileExtension;
                            ImageHelper.MakeThumbnailImage(this.saveFileFullPath, nailPath, maxWidth, maxWidth, ThumbnailType.WidthFix);
                            image.Dispose();
                            System.IO.File.Delete(filePath);         //删除原图
                            System.IO.File.Move(nailPath, filePath); //重命名压缩后的文件
                        }
                        image.Dispose();
                    }

                    //添加水印
                    string sFileName = System.IO.Path.GetFileNameWithoutExtension(fileName) + "_wm" + this.fileExtension;
                    string newPath   = System.IO.Path.Combine(this.saveFileFolderPath, sFileName);
                    if (waterType == 2)
                    {
                        ImageHelper.AddTextWater(saveFileFullPath, newPath, waterPossition, text, textFont, textColor, textSize);
                    }
                    else
                    {
                        ImageHelper.AddImageWater(saveFileFullPath, newPath, waterPossition, waterPhoto);
                    }
                    //删除没上水印的老图
                    //if (System.IO.File.Exists(saveFileFullPath))
                    //{
                    //    System.IO.File.Delete(saveFileFullPath);
                    //}

                    info = new FileInfo(newPath);
                }
            }
            catch
            {
                throw;
            }
            return(info);
        }
Ejemplo n.º 5
0
        public FileInfo SaveAs(int waterType, int waterPossition, string text, string textFont, int textSize, string textColor, string waterPhoto)
        {
            HttpFileCollection files = HttpContext.Current.Request.Files;
            FileInfo           info  = null;

            try
            {
                for (int i = 0; i < files.Count; i++)
                {
                    this.postedFile    = files[i];
                    this.localFilePath = this.postedFile.FileName;
                    if ((this.localFilePath == null) || (this.localFilePath == ""))
                    {
                        throw new Exception("不能上传空文件");
                    }
                    this.localFileLength = this.postedFile.ContentLength;
                    if (this.localFileLength >= (this.sizes * 0x400))
                    {
                        throw new Exception("上传的文件不能大于:" + this.sizes + "KB");
                    }
                    this.saveFileFolderPath = this.GetSaveFileFolderPath();
                    this.localFileName      = System.IO.Path.GetFileName(this.postedFile.FileName);
                    this.fileExtension      = FileHelper.GetFileExtension(this.localFileName);
                    if (this.fileType.ToLower().IndexOf(this.fileExtension.ToLower()) == -1)
                    {
                        throw new Exception("目前本系统支持的格式为:" + this.fileType);
                    }
                    this.saveFileName     = FileHelper.CreateFileName(this.fileNameType, this.localFileName, this.fileExtension);
                    this.saveFileFullPath = this.saveFileFolderPath + this.saveFileName;
                    this.postedFile.SaveAs(this.saveFileFullPath);

                    var imgTypes = ".jpg|.gif|.bmp|.png|.jpeg";
                    if (imgTypes.IndexOf(this.fileExtension.ToLower()) != -1) //必须是图片类型才能加压缩
                    {
                        if (allImageIsNail == 1)                              //如果网站设置开启压缩图片
                        {
                            Image image = Image.FromFile(this.saveFileFullPath);
                            if (image.Width > maxWidth)//如果图片超出设置的编辑器图片宽度,将图片压缩
                            {
                                string filePath = this.saveFileFolderPath + this.saveFileName;
                                string nailPath = this.saveFileFolderPath + "temp_nail" + this.fileExtension;
                                ImageHelper.MakeThumbnailImage(this.saveFileFullPath, nailPath, maxWidth, maxWidth, ThumbnailType.WidthFix);
                                image.Dispose();
                                System.IO.File.Delete(filePath);         //删除原图
                                System.IO.File.Move(nailPath, filePath); //重命名压缩后的文件
                            }
                            image.Dispose();
                        }

                        //添加水印
                        string sFileName = System.IO.Path.GetFileNameWithoutExtension(saveFileName) + "_wm" + this.fileExtension;
                        string newPath   = System.IO.Path.Combine(this.saveFileFolderPath, sFileName);
                        if (waterType == 2)
                        {
                            ImageHelper.AddTextWater(saveFileFullPath, newPath, waterPossition, text, textFont, textColor, textSize);
                        }
                        else
                        {
                            ImageHelper.AddImageWater(saveFileFullPath, newPath, waterPossition, waterPhoto);
                        }
                        //删除没上水印的老图
                        //if (System.IO.File.Exists(saveFileFullPath))
                        //{
                        //    System.IO.File.Delete(saveFileFullPath);
                        //}

                        info = new FileInfo(newPath);
                    }
                }
            }
            catch
            {
                throw;
            }
            return(info);
        }