Exemplo n.º 1
0
        private void GetScriptByModuleName(EasyOne.Model.Accessories.FileInfo fileInfo)
        {
            string str  = BasePage.RequestString("ReturnJSFunction");
            string str2 = BasePage.RequestString("CustomReturnJSFunction");

            if (string.IsNullOrEmpty(str))
            {
                str = "DealwithUpload";
            }
            StringBuilder builder = new StringBuilder();

            builder.Append("<script language=\"javascript\" type=\"text/javascript\">");
            builder.Append("  parent." + str + "(\"" + fileInfo.Path + "\",\"" + fileInfo.Size.ToString() + "\",\"" + fileInfo.Id.ToString() + "\");");
            if (!string.IsNullOrEmpty(str2))
            {
                builder.Append("  parent." + str2 + "(\"" + fileInfo.Path + "\",\"" + fileInfo.Size.ToString() + "\",\"" + fileInfo.Id.ToString() + "\");");
            }
            builder.Append("</script>");
            this.Page.ClientScript.RegisterStartupScript(base.GetType(), "UpdateParent", builder.ToString());
        }
 protected void BtnUpload_Click(object sender, EventArgs e)
 {
     if (!SiteConfig.SiteOption.EnableUploadFiles)
     {
         this.LblMessage.Text = "权限错误:你当前的网站没有开启上传功能,请检查你的网站配置。";
     }
     else
     {
         string str = BasePage.RequestString("ReturnJSFunction");
         int    num = DataConverter.CLng(base.Request.Form["ThumbIndex"]);
         if (string.IsNullOrEmpty(str))
         {
             str = "DealwithUpload";
         }
         StringBuilder builder = new StringBuilder();
         builder.Append("<script language=\"javascript\" type=\"text/javascript\">");
         int           num2     = 0;
         StringBuilder builder2 = new StringBuilder();
         if (!PEContext.Current.Admin.Identity.IsAuthenticated)
         {
             int uploadSize = PEContext.Current.User.UserInfo.UserPurview.UploadSize;
             if (this.m_PhotoSize > uploadSize)
             {
                 this.m_PhotoSize = uploadSize;
             }
         }
         for (int i = 0; i < 10; i++)
         {
             num2++;
             System.Web.UI.WebControls.FileUpload upload = (System.Web.UI.WebControls.FileUpload) this.FindControl("FileUpload" + i.ToString());
             if (upload.HasFile)
             {
                 string str2 = Path.GetExtension(upload.FileName).ToLower();
                 if (!this.CheckFilePostfix(str2.Replace(".", "")))
                 {
                     builder2.Append("文件" + upload.FileName + "上传文件类型不对!必须上传" + this.m_FileExtArr + @"的后缀名!\n");
                 }
                 else if (((int)upload.FileContent.Length) > (this.m_PhotoSize * 0x400))
                 {
                     builder2.Append("文件" + upload.FileName + "请上传小于" + this.m_PhotoSize.ToString() + @"KB的文件!\n");
                 }
                 else
                 {
                     string str3     = DataSecurity.MakeFileRndName() + i.ToString();
                     string filename = FileSystemObject.CreateFileFolder((VirtualPathUtility.AppendTrailingSlash(SiteConfig.SiteOption.UploadDir) + this.FileSavePath(upload.FileName)).Replace("//", "/"), HttpContext.Current) + str3 + str2;
                     upload.SaveAs(filename);
                     Thumbs.GetThumbsPath(this.m_ShowPath + str3 + str2, this.m_ShowPath + str3 + "_S" + str2);
                     if (this.m_Watermark)
                     {
                         WaterMark.AddWaterMark(this.m_ShowPath + str3 + str2);
                     }
                     EasyOne.Model.Accessories.FileInfo fileInfo = new EasyOne.Model.Accessories.FileInfo();
                     fileInfo.Name  = upload.FileName;
                     fileInfo.Path  = this.m_ShowPath + str3 + str2;
                     fileInfo.Size  = (int)upload.FileContent.Length;
                     fileInfo.Quote = 1;
                     Files.Add(fileInfo);
                     if (i == num)
                     {
                         builder.Append("parent." + str + "ChangeThumbField(\"" + fileInfo.Path + "\",\"" + this.m_ShowPath + str3 + "_S" + str2 + "\");");
                     }
                     else
                     {
                         builder.Append("parent." + str + "DealwithUpload(\"" + fileInfo.Path + "\",\"" + fileInfo.Size.ToString() + "\",\"" + fileInfo.Id.ToString() + "\",\"" + this.m_ShowPath + str3 + "_S" + str2 + "\");");
                     }
                     builder2.Append("文件" + upload.FileName + @"上传成功!\n");
                 }
             }
         }
         if (builder2.Length > 0)
         {
             builder.Append("parent." + str + "ErrMessage(\"" + builder2.ToString() + "\");");
         }
         builder.Append("</script>");
         this.Page.ClientScript.RegisterStartupScript(base.GetType(), "UpdateParent", builder.ToString());
     }
 }
Exemplo n.º 3
0
        protected void BtnUpload_Click(object sender, EventArgs e)
        {
            if (!this.FupFile.HasFile)
            {
                this.ReturnManage("上传失败,重新上传。");
                return;
            }
            int  uploadFileMaxSize = 0;
            int  uploadSize        = 0;
            bool flag  = false;
            bool flag2 = false;

            if (!SiteConfig.SiteOption.EnableUploadFiles)
            {
                this.ReturnManage("权限错误:对不起网站没有开启上传权限。");
                return;
            }
            if (!PEContext.Current.Admin.Identity.IsAuthenticated)
            {
                if (!PEContext.Current.User.Identity.IsAuthenticated)
                {
                    UserGroupsInfo userGroupById = UserGroups.GetUserGroupById(-2);
                    if (string.IsNullOrEmpty(userGroupById.GroupSetting))
                    {
                        this.ReturnManage("匿名会员组不存在!");
                        return;
                    }
                    UserPurviewInfo groupSetting = UserGroups.GetGroupSetting(userGroupById.GroupSetting);
                    if (groupSetting.IsNull)
                    {
                        this.ReturnManage("匿名会员组没有进行权限设置!");
                        return;
                    }
                    if (!groupSetting.EnableUpload)
                    {
                        this.ReturnManage("匿名会员组没有开启上传权限!");
                        return;
                    }
                    uploadSize = groupSetting.UploadSize;
                }
                else
                {
                    if (!PEContext.Current.User.UserInfo.UserPurview.EnableUpload)
                    {
                        this.ReturnManage("所属会员组没有开启上传权限!");
                        return;
                    }
                    uploadSize = PEContext.Current.User.UserInfo.UserPurview.UploadSize;
                }
            }
            string str = Path.GetExtension(this.FupFile.FileName).ToLower();

            if (!this.CheckFilePostfix(str.Replace(".", "")))
            {
                this.ReturnManage("上传文件类型不对!必须上传" + this.m_FileExtArr + "的后缀名!");
                return;
            }
            if (string.Compare(this.m_ModuleName, "Node", StringComparison.OrdinalIgnoreCase) == 0)
            {
                FieldInfo           fieldInfoByFieldName = Field.GetFieldInfoByFieldName(this.m_ModelId, this.m_FieldName);
                Collection <string> settings             = fieldInfoByFieldName.Settings;
                switch (fieldInfoByFieldName.FieldType)
                {
                case FieldType.PictureType:
                    uploadFileMaxSize = DataConverter.CLng(settings[1]);
                    flag2             = DataConverter.CBoolean(settings[4]);
                    flag = DataConverter.CBoolean(settings[5]);
                    goto Label_01EA;

                case FieldType.FileType:
                    uploadFileMaxSize = DataConverter.CLng(settings[0]);
                    goto Label_01EA;
                }
            }
            else
            {
                uploadFileMaxSize = SiteConfig.SiteOption.UploadFileMaxSize;
            }
Label_01EA:
            if (!PEContext.Current.Admin.Identity.IsAuthenticated && (uploadFileMaxSize > uploadSize))
            {
                uploadFileMaxSize = uploadSize;
            }
            if (((int)this.FupFile.FileContent.Length) > (uploadFileMaxSize * 0x400))
            {
                this.ReturnManage("请上传小于" + uploadFileMaxSize.ToString() + "KB的文件!");
            }
            else
            {
                string str2     = DataSecurity.MakeFileRndName();
                string filename = FileSystemObject.CreateFileFolder((VirtualPathUtility.AppendTrailingSlash(SiteConfig.SiteOption.UploadDir) + this.FileSavePath()).Replace("//", "/"), HttpContext.Current) + str2 + str;
                this.FupFile.SaveAs(filename);
                string thumbnailPath = "";
                if (flag)
                {
                    thumbnailPath = this.m_ShowPath + str2 + "_S" + str;
                    Thumbs.GetThumbsPath(this.m_ShowPath + str2 + str, thumbnailPath);
                }
                else
                {
                    thumbnailPath = this.m_ShowPath + str2 + str;
                }
                if (flag2)
                {
                    WaterMark.AddWaterMark(this.m_ShowPath + str2 + str);
                }
                EasyOne.Model.Accessories.FileInfo fileInfo = new EasyOne.Model.Accessories.FileInfo();
                fileInfo.Name  = this.FupFile.FileName;
                fileInfo.Path  = thumbnailPath;
                fileInfo.Size  = (int)this.FupFile.FileContent.Length;
                fileInfo.Quote = 1;
                if (string.Compare(this.m_ModuleName, "soft", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    Files.Add(fileInfo);
                }
                this.GetScriptByModuleName(fileInfo);
                this.ReturnManage("上传成功!");
            }
        }