예제 #1
0
        /// <returns>上传成功返回"",并填充 UploadFile(AspNet上传控件专用)</returns>
        /// <param name="oFile">System.Web.HttpPostedFile</param>
        /// <param name="vid">上传配置模块id,即Id</param>
        /// <param name="key">随机key</param>
        /// <param name="userId">上传者id</param>
        /// <param name="userName">上传者UserName</param>
        /// <param name="m_r">UploadFile</param>
        /// <param name="userType">0=未知,1=后台管理员上传,2=前台会员上传</param>
        /// <returns>上传成功返回"",并填充 UploadFile</returns>
        public string Upload_AspNet(System.Web.HttpPostedFile oFile, int vid, string key, int userId, string userName,
                                    UploadFile m_r, int userType = 1)
        {
            #region 检查参数
            //---------------------------------------------------
            if (vid < 1 || key.Length < 10)
            {
                return("缺少参数:key或sid");
            }


            //---------------------------------------------------
            UploadConfig mC = Read_UploadConfig(vid);
            if (mC.Id != vid)
            {
                return("缺少参数:Id!");
            }

            if (mC.IsPost != 1)
            {
                return("系统暂时禁止上传文件2!");
            }

            if (mC.IsEditor == 1)
            {
                return("非编辑器类别!");
            }
            #endregion

            //---------------------------------------------------
            #region 检查登陆
            m_r.UserId = 0;
            if (mC.UserType == 1)//管理员
            {
                if (userType == 1)
                {
                    m_r.UserId   = userId;
                    m_r.UserName = userName;
                }
            }
            else
            {
                if (userType == 2)//一般会员
                {
                    m_r.UserId   = userId;
                    m_r.UserName = userName;
                }
            }

            if (m_r.UserId == 0)
            {
                return("您的权限不足!");
            }
            #endregion

            //------------------------------------------------
            #region 设置上传参数
            var oUp = new Uploader();

            oUp.IsEnabled    = true;
            oUp.IsChkSrcPost = true;
            oUp.CutType      = ConvertHelper.Cint0(mC.CutType);
            oUp.AllowedExt   = Get_Ext(mC.UploadType_TypeKey);
            oUp.MaxSize      = (mC.UploadType_TypeKey == "image") ? ConvertHelper.Cint0(mC.PicSize) : ConvertHelper.Cint0(mC.FileSize);
            oUp.SavePath     = mC.SaveDir;


            oUp.SetPic((mC.IsFixPic == 1), ConvertHelper.Cint0(mC.PicWidth), ConvertHelper.Cint0(mC.PicHeight), ConvertHelper.Cint0(mC.PicQuality));
            oUp.SetBig((mC.IsBigPic == 1), ConvertHelper.Cint0(mC.BigWidth), ConvertHelper.Cint0(mC.BigHeight), ConvertHelper.Cint0(mC.BigQuality));
            oUp.SetMid((mC.IsMidPic == 1), ConvertHelper.Cint0(mC.MidWidth), ConvertHelper.Cint0(mC.MidHeight), ConvertHelper.Cint0(mC.MidQuality));
            oUp.SetMin((mC.IsMinPic == 1), ConvertHelper.Cint0(mC.MinWidth), ConvertHelper.Cint0(mC.MinHeight), ConvertHelper.Cint0(mC.MinQuality));
            oUp.SetHot((mC.IsHotPic == 1), ConvertHelper.Cint0(mC.HotWidth), ConvertHelper.Cint0(mC.HotHeight), ConvertHelper.Cint0(mC.HotQuality));

            oUp.IsWaterPic = (mC.IsWaterPic == 1);
            #endregion

            #region
            //------------------------------------------------
            bool isOk = oUp.UploadFile(oFile);
            if (!isOk)
            {
                //上传出错
                return(StringHelper.XssTextClear(oUp.GetErrMsg() + mC.Id));
            }
            #endregion

            //----------------------------------------------------------------
            #region 保存入数据库
            m_r.UploadConfig_Id = mC.Id;
            m_r.JoinName        = mC.JoinName;
            m_r.JoinId          = 0;

            m_r.UserType = mC.UserType;
            m_r.UserIp   = IpHelper.GetUserIp();
            m_r.AddDate  = DateTime.Now;
            m_r.InfoText = "";
            m_r.RndKey   = key;

            m_r.Name = oUp.NewFile;
            m_r.Path = oUp.NewPath;
            m_r.Src  = StringHelper.Left(oUp.SrcName, 90, false);
            m_r.Ext  = oUp.FileExt;

            m_r.Size      = oUp.GetFileSize();
            m_r.PicWidth  = oUp.NewWidth;
            m_r.PicHeight = oUp.NewHeight;

            //保存入数据库
            Add_UploadFile(m_r);
            #endregion

            //------------------------------------
            //上传成功,输出结果
            return("");
        }
예제 #2
0
        /// <returns>上传成功返回"",并填充 UploadFile</returns>
        /// <param name="vid">上传配置模块id,即Id</param>
        /// <param name="key">随机key</param>
        /// <param name="userId">上传者id</param>
        /// <param name="userName">上传者UserName</param>
        /// <param name="m_r">UploadFile</param>
        /// <param name="filePostName">上传文件框控件的名称,默认"imgFile",uploadify 默认 "Filedata"</param>
        /// <param name="userType">0=未知,1=后台管理员上传,2=前台会员上传</param>
        /// <param name="isEditor">从GetAction返回判断是否为编辑器</param>
        /// <param name="isSwf">是否通过flash上传</param>
        /// <returns>上传成功返回"",并填充 UploadFile</returns>
        public string Upload_Web(int vid, string key, int userId, string userName,
                                 UploadFile m_r, string filePostName = "imgFile",
                                 int userType = 1, bool isEditor = false, bool isSwf = false)
        {
            #region 检查参数
            //---------------------------------------------------
            if (vid < 1 || key.Length < 10)
            {
                return("缺少参数:key或sid");
            }

            string dir = RequestHelper.GetKeyChar("dir");//编辑器专用:image,flash,media,file
            if (dir.Length > 0)
            {
                if (Array.IndexOf("image,flash,media,file".Split(','), dir) == -1)
                {
                    return("缺少参数:dir");
                }
            }
            //---------------------------------------------------
            UploadConfig mC = Read_UploadConfig(vid);
            if (mC == null || mC.Id != vid)
            {
                return("缺少参数:上传配置Id设置不正确!");
            }

            if (mC.IsPost != 1)
            {
                return("系统暂时禁止上传文件2!");
            }

            if (mC.IsEditor == 1 && isEditor == false)
            {
                return("非编辑器类别!");
            }


            if (mC.IsSwf == 0 && isSwf == true)
            {
                return("不能从flash中上传!");
            }
            #endregion

            //---------------------------------------------------
            #region 检查登陆
            m_r.UserId = 0;
            if (mC.UserType == 1)//管理员
            {
                if (userType == 1)
                {
                    m_r.UserId   = userId;
                    m_r.UserName = userName;
                }
            }
            else
            {
                if (userType == 2)//一般会员
                {
                    m_r.UserId   = userId;
                    m_r.UserName = userName;
                }
            }

            if (m_r.UserId == 0)
            {
                return("您的权限不足!");
            }
            #endregion

            //------------------------------------------------
            #region 设置上传参数
            var oUp = new Uploader();

            oUp.IsEnabled = true;
            if (isSwf)
            {
                oUp.IsChkSrcPost = false;  //如果swf提交,必须设置为 o_up.isChkSrcPost = false;
            }
            else
            {
                //o_up.isChkSrcPost = (m_c.isChkSrcPost == "1");  //如果swf提交,必须设置为 o_up.isChkSrcPost = false;
                oUp.IsChkSrcPost = true;
            }

            oUp.CutType = ConvertHelper.Cint0(mC.CutType);

            oUp.FilePostName = filePostName;

            if (isEditor && mC.UploadType_TypeKey == "editor")
            {
                mC.UploadType_TypeKey = dir;
            }
            oUp.AllowedExt = Get_Ext(mC.UploadType_TypeKey);
            oUp.MaxSize    = (mC.UploadType_TypeKey == "image") ? ConvertHelper.Cint0(mC.PicSize) : ConvertHelper.Cint0(mC.FileSize);
            oUp.SavePath   = mC.SaveDir;


            oUp.SetPic((mC.IsFixPic == 1), ConvertHelper.Cint0(mC.PicWidth), ConvertHelper.Cint0(mC.PicHeight), ConvertHelper.Cint0(mC.PicQuality));
            oUp.SetBig((mC.IsBigPic == 1), ConvertHelper.Cint0(mC.BigWidth), ConvertHelper.Cint0(mC.BigHeight), ConvertHelper.Cint0(mC.BigQuality));
            oUp.SetMid((mC.IsMidPic == 1), ConvertHelper.Cint0(mC.MidWidth), ConvertHelper.Cint0(mC.MidHeight), ConvertHelper.Cint0(mC.MidQuality));
            oUp.SetMin((mC.IsMinPic == 1), ConvertHelper.Cint0(mC.MinWidth), ConvertHelper.Cint0(mC.MinHeight), ConvertHelper.Cint0(mC.MinQuality));
            oUp.SetHot((mC.IsHotPic == 1), ConvertHelper.Cint0(mC.HotWidth), ConvertHelper.Cint0(mC.HotHeight), ConvertHelper.Cint0(mC.HotQuality));

            oUp.IsWaterPic = (mC.IsWaterPic == 1);
            #endregion

            #region
            //------------------------------------------------
            bool isOk = oUp.UploadFile();
            if (!isOk)
            {
                //上传出错
                return(StringHelper.XssTextClear(oUp.GetErrMsg() + mC.Id));
            }
            #endregion

            //----------------------------------------------------------------
            #region 保存入数据库
            m_r.UploadConfig_Id = mC.Id;
            m_r.JoinName        = mC.JoinName;
            m_r.JoinId          = 0;

            m_r.UserType = mC.UserType;
            m_r.UserIp   = IpHelper.GetUserIp();
            m_r.AddDate  = DateTime.Now;
            m_r.InfoText = "";
            m_r.RndKey   = key;

            m_r.Name = oUp.NewFile;
            m_r.Path = oUp.NewPath;
            m_r.Src  = StringHelper.Left(oUp.SrcName, 90);
            m_r.Ext  = oUp.FileExt;

            m_r.Size      = oUp.GetFileSize();
            m_r.PicWidth  = oUp.NewWidth;
            m_r.PicHeight = oUp.NewHeight;

            //保存入数据库
            Add_UploadFile(m_r);
            #endregion

            //------------------------------------
            //上传成功,输出结果
            return("");
        }