コード例 #1
0
        protected void BtnUpload_Click(object sender, EventArgs e)
        {
            long size = FupFile.FileContent.Length;

            if (size > 10 * 1024 * 1024)
            {
                function.Script(this, "alert('文件不能大于10mb');"); return;
            }
            M_ModelField fieldmod = fieldBll.GetModelByFieldName(ModelID, FieldName);

            if (fieldmod == null)
            {
                return;
            }
            if (SafeSC.FileNameCheck(FupFile.FileName))
            {
                function.Script(this, "alert('此文件格式不允许上传!');"); return;
            }
            if (fieldmod.FieldType.Equals("SqlType") && !SafeSC.IsImage(FupFile.FileName))
            {
                function.Script(this, "alert('只能上传图片!');"); return;
            }
            string content  = fieldmod.Content;
            Stream filedata = FupFile.FileContent;

            byte[] filebyte = new byte[filedata.Length];
            filedata.Read(filebyte, 0, filebyte.Length);
            function.Script(this, "parent.DealwithUploadPic('" + FupFile.FileName + "|" + Convert.ToBase64String(filebyte) + "','FIT_" + FieldName + "');");
            function.Script(this, "parent.DealwithUploadPic('" + FupFile.FileName + "','txt_" + FieldName + "');");
            LblMessage.Text = "文件上传成功";
        }
コード例 #2
0
        protected void BtnUpload_Click(object sender, EventArgs e)
        {
            if (FType == 1 || FType == 4)
            {
                this.m_FileExtArr = "gif|jpg|png|swf";
            }
            else
            {
                this.m_FileExtArr = "gif|jpg|png|docx|rar|doc";
            }
            string str2 = Path.GetExtension(File_UP.FileName).ToLower();

            if (!this.CheckFilePostfix(str2.Replace(".", "")))
            {
                this.ReturnManage("上传的文件不是符合扩展名" + this.m_FileExtArr + "的文件");
            }
            else
            {
                string fname    = DateTime.Now.ToString("yyyyMMddHHmmss") + function.GetRandomString(4) + Path.GetExtension(File_UP.FileName);
                string savePath = "";
                if (SafeSC.IsImage(File_UP.FileName))
                {
                    System.Drawing.Image img = System.Drawing.Image.FromStream(File_UP.PostedFile.InputStream);
                    img      = ImgHelper.AddWater(img);
                    savePath = ImgHelper.SaveImage(FileSavePath() + fname, img);
                }
                else
                {
                    savePath = SafeSC.SaveFile(savePath, File_UP, fname);
                }
                this.GetScriptByModuleName(savePath);
                this.ReturnManage("文件上传成功");
            }
        }
コード例 #3
0
        protected void BtnUpload_Click(object sender, EventArgs e)
        {
            int sizes = 0;

            if (!FupFile.HasFile)
            {
                ReturnManage("请指定一个上传文件");
                return;
            }
            //if (!SafeSC.IsImage(FupFile.FileName)) { function.WriteErrMsg("只能上传图片文件"); }
            string ext = Path.GetExtension(FupFile.FileName).ToLower();

            m_MaxFileSize = DataConverter.CLng(SiteConfig.SiteOption.UploadPicMaxSize);
            if (((int)FupFile.FileContent.Length) > (m_MaxFileSize * 0x400))
            {
                ReturnManage("上传的文件超过限制的" + m_MaxFileSize + "KB大小");
                return;
            }
            string ranFName   = DataSecurity.MakeFileRndName() + ext;//文件名
            string foldername = base.Request.PhysicalApplicationPath.TrimEnd('\\') + (VirtualPathUtility.AppendTrailingSlash(SiteConfig.SiteOption.UploadDir) + FileSavePath()).Replace("/", "\\");
            string fileName   = FileSystemObject.CreateFileFolder(foldername, HttpContext.Current);
            string savePath   = SafeSC.SaveFile(function.PToV(fileName), FupFile, ranFName);

            if (WaterModuleConfig.WaterConfig.IsUsed && SafeSC.IsImage(FupFile.FileName) && RadioButtonList1.SelectedValue == "1")
            {
                savePath = ImgHelper.AddWater(savePath);
            }
            sizes = (int)FupFile.FileContent.Length;
            GetScriptByModuleName(savePath.Replace(SiteConfig.SiteOption.UploadDir, ""), sizes);
            ReturnManage("文件上传成功");
        }
コード例 #4
0
        protected void BtnUpload_Click(object sender, EventArgs e)
        {
            int sizes = 0;

            if (!File_UP.HasFile)
            {
                ReturnManage("请指定一个上传文件");
                return;
            }
            //if (!SafeSC.IsImage(FupFile.FileName)) { function.WriteErrMsg("只能上传图片文件"); }
            string fname    = DateTime.Now.ToString("yyyyMMddHHmmss") + function.GetRandomString(4) + Path.GetExtension(File_UP.FileName);
            string savePath = "";

            if (SafeSC.IsImage(File_UP.FileName))
            {
                System.Drawing.Image img = System.Drawing.Image.FromStream(File_UP.PostedFile.InputStream);
                if (Request.Form["water_rad"].Equals("1"))
                {
                    img = ImgHelper.AddWater(img);
                }
                if (SiteConfig.ThumbsConfig.ThumbsWidth > 0 || SiteConfig.ThumbsConfig.ThumbsHeight > 0)
                {
                    img = imgHelp.ZoomImg(img, SiteConfig.ThumbsConfig.ThumbsHeight, SiteConfig.ThumbsConfig.ThumbsWidth);
                }
                System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(img);
                savePath = imgHelp.SaveImg(FileSavePath() + fname, bmp);
            }
            else
            {
                RepStr("仅允许上传图片文件");
            }
            sizes = (int)File_UP.FileContent.Length;
            GetScriptByModuleName(savePath.Replace(SiteConfig.SiteOption.UploadDir, ""), sizes);
            ReturnManage("文件上传成功");
        }
コード例 #5
0
ファイル: ComController.cs プロジェクト: baixue001/IPS
        public string SaveFile()
        {
            C_SFileUP model     = JsonConvert.DeserializeObject <C_SFileUP>(RequestEx["model"]);
            var       file      = Request.Form.Files["file"];
            Stream    stream    = file.OpenReadStream();
            int       conLength = (int)Request.ContentLength;
            //=================================
            string result = "";

            if (Request.ContentLength < 100 || string.IsNullOrEmpty(file.FileName))
            {
                return("");
            }
            string fname = DateTime.Now.ToString("yyyyMMddHHmm") + function.GetRandomString(4) + Path.GetExtension(file.FileName);

            switch (model.FileType)
            {
            case "img":
            {
                if (!SafeSC.IsImage(file.FileName))
                {
                    throw new Exception(Path.GetExtension(file.FileName) + "不是有效的图片格式!");
                }
                //ImgHelper imghelp = new ImgHelper();
                //if (IsCompress)//压缩与最大比只能有一个生效
                //{
                //    imghelp.CompressImg(FileUp_File.PostedFile, 1000, vpath);
                //}
                bool hasSave = false;
                //if (model.MaxWidth > 0 || model.MaxHeight > 0)
                //{
                //    System.Drawing.Image img = System.Drawing.Image.FromStream(file.InputStream);
                //    img = imghelp.ZoomImg(img, model.MaxHeight, model.MaxWidth);
                //    result = ImgHelper.SaveImage(GetSaveDir(model.SaveType) + fname, img);
                //    hasSave = true;
                //}
                if (!hasSave)
                {
                    result = SafeC.SaveFile(GetSaveDir(model.SaveType), fname, stream, conLength);
                }
            }
            break;
                //case "office":
                //    {
                //        string[] exname = "doc|docx|xls|xlsx".Split('|');
                //        if (!exname.Contains(Path.GetExtension(file.FileName))) { throw new Exception("必须上传doc|docx|xls|xlsx格式的文件!"); return ""; }
                //        result = ZoomLa.BLL.SafeSC.SaveFile(GetSaveDir(model.SaveType), fname, stream, conLength);
                //    }
                //    break;
                //case "all":
                //default:
                //    {
                //        result = ZoomLa.BLL.SafeSC.SaveFile(GetSaveDir(model.SaveType), fname, file.OpenReadStream(), conLength);
                //    }
                //    break;
            }
            return(result);
        }
コード例 #6
0
 public string SaveFile()
 {
     if (string.IsNullOrEmpty(FVPath_T.Text) && !IsNull)
     {
         function.WriteErrMsg("请选择上传文件!");
     }
     if (FileUp_File.HasFile)
     {
         string filename = function.GetFileName() + Path.GetExtension(FileUp_File.FileName);
         if (IsRelName)
         {
             filename = FileUp_File.FileName;
         }
         if (FType == FileType.Img && !SafeSC.IsImage(FileUp_File.FileName))
         {
             function.WriteErrMsg("必须上传图片格式的文件!");
         }
         if (FType == FileType.Img)
         {
             string    vpath   = "";
             ImgHelper imghelp = new ImgHelper();
             //if (IsCompress)//压缩与最大比只能有一个生效
             //{
             //    imghelp.CompressImg(FileUp_File.PostedFile, 1000, vpath);
             //}
             if (MaxWidth > 0)
             {
                 vpath = SafeSC.SaveFile(SaveUrl, FileUp_File, filename);
                 using (FileStream fs = new FileStream(Server.MapPath(vpath), FileMode.Open, FileAccess.Read))
                 {
                     System.Drawing.Image img = System.Drawing.Image.FromStream(fs);
                     double ImgPercent        = (double)MaxWidth / (double)img.Width;
                     int    width             = (int)(img.Width * ImgPercent);
                     int    height            = (int)(img.Height * ImgPercent);
                     img.Dispose();
                     Bitmap bmp        = imghelp.ZoomImg(vpath, height, width);
                     string cutedVPath = SaveUrl + function.GetRandomString(6) + Path.GetExtension(filename);
                     imghelp.SaveImg(cutedVPath, bmp);
                     FileUrl = cutedVPath; return(FileUrl);
                 }
             }
         }
         if (FType == FileType.Office && !exname.Contains(Path.GetExtension(FileUp_File.FileName)))
         {
             function.WriteErrMsg("必须上传office格式的文件!");
         }
         FileUrl = SafeSC.SaveFile(SaveUrl, FileUp_File, filename);
         //FileUrl = SaveUrl + filename;
         //if (!Directory.Exists(function.VToP(SaveUrl))) { SafeSC.CreateDir(SaveUrl); }
         //if (!FileUp_File.SaveAs(FileUrl)) { function.WriteErrMsg(FileUp_File.ErrorMsg); }
     }
     return(FileUrl);
 }
コード例 #7
0
ファイル: ThumbHelper.cs プロジェクト: baixue001/IPS
        /// <summary>
        ///  创建缩图文件
        /// </summary>
        /// <param name="vpath">topimg的路径</param>
        /// <param name="thumb">压图字段的值</param>
        /// <returns>处理后的图片路径</returns>
        public static string Thumb_Compress(string vpath, string thumb, int destWidth, int destHeight)
        {
            if (string.IsNullOrEmpty(vpath))
            {
                return(thumb);
            }
            if (!File.Exists(function.VToP(vpath)))
            {
                return(thumb);
            }
            if (!SafeSC.IsImage(vpath))
            {
                return(thumb);
            }
            //----------------------------
            ImgHelper imghelp = new ImgHelper();

            //为空或不存在,则重新生成缩图名称
            if (string.IsNullOrEmpty(thumb) || !File.Exists(function.VToP(thumb)))
            {
                string fname       = Path.GetFileNameWithoutExtension(vpath);
                string ext         = Path.GetExtension(vpath);
                string thumb_fname = fname + ".thumb" + ext;
                thumb = vpath.Substring(0, vpath.LastIndexOf("/") + 1) + thumb_fname;
            }
            else
            {
                return(thumb);
            }
            //如图片小于设定,则也不压缩,直接返回其路径即可
            //int destWidth = SiteConfig.ThumbsConfig.ThumbsWidth;
            //int destHeight = SiteConfig.ThumbsConfig.ThumbsHeight;
            //生成缩图保存
            Image img = ImgHelper.ReadImgToMS(vpath);

            if ((destWidth + destHeight) < 1)
            {
                ImgHelper.SaveImage(thumb, img);
            }
            else if (img.Width <= destWidth && img.Height <= destHeight)
            {
                ImgHelper.SaveImage(thumb, img);
            }
            else
            {
                Bitmap bmp = imghelp.ZoomImg(vpath, destHeight, destWidth);
                imghelp.SaveImg(thumb, bmp);
            }
            return(thumb);
        }
コード例 #8
0
        public DataTable GetDTFromPlat()
        {
            B_Blog_Msg msgBll = new B_Blog_Msg();
            M_Blog_Msg msgMod = msgBll.SelReturnModel(Sid);
            DataTable  dt     = DTFormat();
            int        index  = 0;

            foreach (string file in msgMod.Attach.Split('|'))
            {
                if (SafeSC.IsImage(file))
                {
                    DataRow dr = dt.NewRow();
                    dr["Index"] = index; index++;
                    dr["Src"]   = file;
                    dt.Rows.Add(dr);
                }
            }
            return(dt);
        }
コード例 #9
0
ファイル: ImgHelper.cs プロジェクト: linrb/CMS-Source-code
        /*---------------从配置文件中增加水印--------------------*/
        /// <summary>
        /// 读取配置文件,增加水印
        /// </summary>
        /// <vpath>需水印图片虚拟路径</vpath>
        /// <returns>水印后的路径</returns>
        public static string AddWater(string svpath)
        {
            if (!SafeSC.IsImage(svpath) || !WaterModuleConfig.WaterConfig.IsUsed)
            {
                return(svpath);
            }
            string sppath   = function.VToP(svpath);
            string vdir     = Path.GetDirectoryName(sppath) + "\\";
            string fname    = "wd_" + Path.GetFileName(svpath);
            string savePath = function.PToV(vdir + fname);

            System.Drawing.Image img = Image.FromFile(sppath);
            img = AddWater(img);
            Bitmap bmp = new Bitmap(img);

            savePath = new ImgHelper().SaveImg(savePath, bmp);
            img.Dispose(); bmp.Dispose();
            return(savePath);
        }
コード例 #10
0
        public MvcHtmlString GetUrl(DataRow dr)
        {
            string result   = "";
            int    filetype = Convert.ToInt32(dr["FileType"]);

            if (filetype == 2)
            {
                result = GroupPic.GetExtNameMini("filefolder");
            }
            else if (SafeSC.IsImage(dr["FileName"].ToString()))
            {
                string imgurl = CurrentDir + dr["SFileName"];
                result = "<img src='" + imgurl + "' style='width:30px;height:30px;display:block;' />";
            }
            else
            {
                result = GroupPic.GetExtNameMini(Path.GetExtension(DataConverter.CStr(dr["FileName"])));
            }
            return(MvcHtmlString.Create(result));
        }
コード例 #11
0
        protected void SFile_Btn_Click(object sender, EventArgs e)
        {
            M_UserInfo mu      = buser.GetLogin();
            ImgHelper  imghelp = new ImgHelper();
            string     fpath   = B_Design_SiteInfo.GetSiteUpDir(mu.SiteID);

            if (!SafeSC.IsImage(SFile_UP.FileName))
            {
                function.WriteErrMsg("上传的图片后缀名不允许");
            }
            if (Path.GetExtension(SFile_UP.FileName).Equals(".gif"))
            {
                fpath = SafeSC.SaveFile(fpath, SFile_UP, function.GetFileName() + Path.GetExtension(SFile_UP.FileName));
            }
            else
            {
                fpath += function.GetFileName() + Path.GetExtension(SFile_UP.FileName);
                imghelp.CompressImg(SFile_UP.PostedFile, 1024, fpath);
            }
            function.Script(this, "setTimeout(function () { updateiurl('" + fpath + "');},50);");
        }
コード例 #12
0
        protected void FileUp_Btn_Click(object sender, EventArgs e)
        {
            M_UserInfo mu = buser.GetLogin();

            if (!FileUp_File.HasFile)
            {
                function.Script(this, "请指定一个上传文件"); return;
            }
            string ext = Path.GetExtension(FileUp_File.FileName).ToLower();
            //if (ext.Equals(".html") || ext.Equals(".html") || ext.Equals(".shtml")) { function.Script(this, "不允许上传html文件"); return; }

            string fname    = DataSecurity.MakeFileRndName() + ext;
            string dirPath  = SiteConfig.SiteOption.UploadDir + "UserUpload/" + mu.UserName + mu.UserID + "/";
            string savePath = SafeSC.SaveFile(dirPath, FileUp_File, fname);

            if (WaterModuleConfig.WaterConfig.IsUsed && SafeSC.IsImage(FileUp_File.FileName))
            {
                savePath = ImgHelper.AddWater(savePath);
            }
            function.Script(this, "ZLIfrField.UploadPic(\"" + savePath + "\",\"" + FieldName + "\");");
            LblMsg_L.Text = "文件上传成功";
        }
コード例 #13
0
        /*---------------从配置文件中增加水印--------------------*/
        /// <summary>
        /// 读取配置文件,增加水印
        /// </summary>
        /// <vpath>需水印图片虚拟路径</vpath>
        /// <returns>水印后的路径</returns>
        public static string AddWater(string svpath)
        {
            if (!SafeSC.IsImage(svpath) || !WaterModuleConfig.WaterConfig.IsUsed)
            {
                return(svpath);
            }
            string[] exps = { ".jpg", ".bmp", ".png" };
            if (!exps.Contains(Path.GetExtension(svpath).ToLower()))
            {
                return(svpath);
            }
            string sppath   = function.VToP(svpath);
            string vdir     = Path.GetDirectoryName(sppath) + "\\";
            string fname    = "wd_" + Path.GetFileName(svpath);
            string savePath = function.PToV(vdir + fname);
            Image  img      = Image.FromFile(sppath);

            img = AddWater(img);
            Bitmap bmp = new Bitmap(img);

            savePath = new ImgHelper().SaveImg(savePath, bmp);
            img.Dispose(); bmp.Dispose();
            return(savePath);
        }
コード例 #14
0
        protected void Save_Btn_Click(object sender, EventArgs e)
        {
            //根据场景和类型来决定存放路径
            Res_UP.SaveUrl = "/UploadFiles/design/res/" + Type_DP.SelectedValue + "/" + Useage_Dp.SelectedValue + "/";
            string vdir = Res_UP.SaveUrl;

            if (Mid > 0)
            {
                resMod = resBll.SelReturnModel(Mid);
            }
            resMod.Name    = Name_T.Text.Replace(" ", "");
            resMod.ZStatus = DataConvert.CLng(Request.Form["zstatus_rad"]);
            resMod.ZType   = Type_DP.SelectedValue;
            resMod.Useage  = Useage_Dp.SelectedValue;
            if (!Res_UP.FVPath.Equals(resMod.VPath, StringComparison.CurrentCultureIgnoreCase))
            {
                if (Res_UP.HasFile)
                {
                    resMod.VPath = Res_UP.SaveFile();
                }
                else
                {
                    resMod.VPath = Res_UP.FVPath;
                }
            }
            //如果是图片资源,并且未指定缩图,则自动生成,否则使用手输的值
            if (resMod.ZType.Equals("img") && SafeSC.IsImage(resMod.VPath) && string.IsNullOrEmpty(PreviewImg_T.Text))
            {
                int width = 0, height = 0;
                switch (resMod.Useage)
                {
                case "bk_h5":
                    width = 200; height = 300;
                    break;

                case "bk_pc":
                    width = 500; height = 280;
                    break;
                }
                string fname = Path.GetFileNameWithoutExtension(resMod.VPath);
                string ext   = Path.GetExtension(resMod.VPath);
                resMod.PreviewImg = imgHelper.SaveImg(vdir + fname + ".thumb" + ext, imgHelper.ZoomImg(resMod.VPath, height, width));
            }
            else
            {
                resMod.PreviewImg = PreviewImg_T.Text;
            }
            resMod.use   = Request.Form["use_chk"];
            resMod.fun   = Request.Form["fun_chk"];
            resMod.style = Request.Form["style_chk"];
            if (Mid > 0)
            {
                resBll.UpdateByID(resMod);
            }
            else
            {
                resMod.UserID = B_Admin.GetLogin().AdminId;
                resBll.Insert(resMod);
            }
            function.WriteSuccessMsg("操作成功", "ResList.aspx");
        }
コード例 #15
0
        protected void BtnUpload_Click(object sender, EventArgs e)
        {
            long size = FupFile.FileContent.Length;

            if (!this.FupFile.HasFile)
            {
                this.ReturnManage("请指定一个上传文件");
            }
            else
            {
                if (!SiteConfig.SiteOption.EnableUploadFiles)
                {
                    this.ReturnManage("本站不允许上传文件!");
                }
                else
                {
                    string str2 = Path.GetExtension(this.FupFile.FileName).ToLower();
                    if (!SafeSC.IsImage(str2))
                    {
                        this.ReturnManage("上传的文件不是符合扩展名" + this.m_FileExtArr + "格式的文件");
                    }
                    else
                    {
                        this.m_FileExtArr  = SiteConfig.SiteOption.UploadFileExts;
                        this.m_MaxFileSize = SiteConfig.SiteOption.UploadPicMaxSize;//DataConverter.CLng(this.ViewState["MaxFileSize"].ToString());
                        if (string.IsNullOrEmpty(this.m_FileExtArr))
                        {
                            this.ReturnManage("要上传文件的字段没有指定上传文件类型");
                        }
                        else
                        {
                            if (((int)this.FupFile.FileContent.Length) > (this.m_MaxFileSize * 0x400))
                            {
                                this.ReturnManage("上传的文件超过限制的" + this.m_MaxFileSize + "KB大小");
                                return;
                            }
                            string str3       = DataSecurity.MakeFileRndName();
                            string foldername = base.Request.PhysicalApplicationPath + (VirtualPathUtility.AppendTrailingSlash(SiteConfig.SiteOption.UploadDir) + this.FileSavePath()).Replace("/", @"\");
                            foldername = foldername.Replace(@"\\", @"\");

                            string filename = FileSystemObject.CreateFileFolder(foldername, HttpContext.Current) + str3 + str2;


                            if (WaterModuleConfig.WaterConfig.IsUsed && (str2 == ".jpg" || str2 == ".png") && HiddenNodeDir.Value != null && HiddenNodeDir.Value != "")
                            {
                                string Testfoldername = "";
                                if (NodeID <= 0)
                                {
                                    Testfoldername = foldername.Replace("UserUpload", "test");
                                }
                                else
                                {
                                    Testfoldername = foldername.Replace(HiddenNodeDir.Value, "test");
                                }
                                string Testfilename = FileSystemObject.CreateFileFolder(Testfoldername, HttpContext.Current) + str3 + str2;
                                this.FupFile.SaveAs(Testfilename);

                                WaterImages dd = new WaterImages();
                                if (WaterModuleConfig.WaterConfig.WaterClass == "1")
                                {
                                    string imgurl = Server.MapPath(WaterModuleConfig.WaterConfig.imgLogo);
                                    int    post   = DataConverter.CLng(WaterModuleConfig.WaterConfig.lopostion);
                                    dd.DrawImage(Testfilename, imgurl, filename);
                                }
                                else
                                {
                                    string waterword = WaterModuleConfig.WaterConfig.WaterWord;
                                    string ziti      = WaterModuleConfig.WaterConfig.WaterWordType;
                                    dd.DrawFont(Testfilename, filename);
                                }
                            }
                            else
                            {
                                this.FupFile.SaveAs(filename);
                            }
                            int    sizes         = (int)this.FupFile.FileContent.Length;
                            string thumbnailPath = "";
                            thumbnailPath = this.m_ShowPath + str3 + str2;
                            this.GetScriptByModuleName(thumbnailPath, sizes);
                            this.ReturnManage("文件上传成功");
                        }
                    }
                }
            }
        }
コード例 #16
0
 public bool isimg(string name)
 {
     return(SafeSC.IsImage(name));
 }
コード例 #17
0
        public string SaveFile()
        {
            //if (string.IsNullOrEmpty(FVPath_T.Text) && !IsNull) { function.WriteErrMsg("请选择上传文件!"); }
            //如未指定上传文件,则返回FVPath中的值,便于清空与拷贝地址进入
            if (!FileUp_File.HasFile)
            {
                return(FVPath);
            }
            string filename = filename = FileUp_File.FileName;

            if (!IsRelName)
            {
                filename = DateTime.Now.ToString("yyyyMMddHHmmss") + function.GetRandomString(4) + Path.GetExtension(FileUp_File.FileName);
            }
            switch (FType)
            {
            case FileType.Img:
            {
                if (!SafeSC.IsImage(FileUp_File.FileName))
                {
                    function.WriteErrMsg(Path.GetExtension(FileUp_File.FileName) + "不是有效的图片格式!");
                }
                ImgHelper imghelp = new ImgHelper();
                //if (IsCompress)//压缩与最大比只能有一个生效
                //{
                //    imghelp.CompressImg(FileUp_File.PostedFile, 1000, vpath);
                //}
                bool hasSave = false;
                if (MaxWidth > 0 || MaxHeight > 0)
                {
                    System.Drawing.Image img = System.Drawing.Image.FromStream(FileUp_File.PostedFile.InputStream);
                    img     = imghelp.ZoomImg(img, MaxHeight, MaxWidth);
                    FileUrl = ImgHelper.SaveImage(SaveUrl + filename, img);
                    hasSave = true;
                }
                if (!hasSave)
                {
                    FileUrl = SafeSC.SaveFile(SaveUrl, FileUp_File, filename);
                }
            }
            break;

            case FileType.Office:
            {
                if (!exname.Contains(Path.GetExtension(FileUp_File.FileName)))
                {
                    function.WriteErrMsg("必须上传doc|docx|xls|xlsx格式的文件!");
                }
                FileUrl = SafeSC.SaveFile(SaveUrl, FileUp_File, filename);
            }
            break;

            default:
            {
                FileUrl = SafeSC.SaveFile(SaveUrl, FileUp_File, filename);
            }
            break;
            }
            //FileUrl = SaveUrl + filename;
            //if (!Directory.Exists(function.VToP(SaveUrl))) { SafeSC.CreateDir(SaveUrl); }
            //if (!FileUp_File.SaveAs(FileUrl)) { function.WriteErrMsg(FileUp_File.ErrorMsg); }
            return(FileUrl);
        }
コード例 #18
0
        public string SaveFile()
        {
            C_SFileUP          model  = JsonConvert.DeserializeObject <C_SFileUP>(Request.Form["model"]);
            HttpPostedFileBase file   = Request.Files["file"];
            string             result = "";

            if (file.ContentLength < 100 || string.IsNullOrEmpty(file.FileName))
            {
                return("");
            }
            string fname = DateTime.Now.ToString("yyyyMMddHHmm") + function.GetRandomString(4) + Path.GetExtension(file.FileName);

            switch (model.FileType)
            {
            case "img":
            {
                // function.WriteErrMsg(Path.GetExtension(file.FileName) + "不是有效的图片格式!");
                if (!SafeSC.IsImage(file.FileName))
                {
                    return("");
                }
                ImgHelper imghelp = new ImgHelper();
                //if (IsCompress)//压缩与最大比只能有一个生效
                //{
                //    imghelp.CompressImg(FileUp_File.PostedFile, 1000, vpath);
                //}
                bool hasSave = false;
                if (model.MaxWidth > 0 || model.MaxHeight > 0)
                {
                    System.Drawing.Image img = System.Drawing.Image.FromStream(file.InputStream);
                    img     = imghelp.ZoomImg(img, model.MaxHeight, model.MaxWidth);
                    result  = ImgHelper.SaveImage(GetSaveDir(model.SaveType) + fname, img);
                    hasSave = true;
                }
                if (!hasSave)
                {
                    result = SafeC.SaveFile(GetSaveDir(model.SaveType), fname, file.InputStream, file.ContentLength);
                }
            }
            break;

            case "office":
            {
                string[] exname = "doc|docx|xls|xlsx".Split('|');
                if (!exname.Contains(Path.GetExtension(file.FileName)))
                {
                    function.WriteErrMsg("必须上传doc|docx|xls|xlsx格式的文件!"); return("");
                }
                // result = SafeC.SaveFile(GetSaveDir(model.SaveType), fname, file.InputStream, file.ContentLength);
            }
            break;

            case "all":
            default:
            {
                // result = SafeC.SaveFile(GetSaveDir(model.SaveType), fname, file.InputStream, file.ContentLength);
            }
            break;
            }
            return(result);
        }