コード例 #1
0
        private void UpLoadPayFile(HttpContext context)
        {
            Model.sysconfig sysConfig = new BLL.sysconfig().loadConfig();
            //检查是否允许匿名上传
            if (!new ManagePage().IsAdminLogin())
            {
                context.Response.Write("{\"status\": 0, \"msg\": \"禁止匿名非法上传!\"}");
                return;
            }
            string fileName     = DTRequest.GetString("name");                                   //文件名
            int    pid          = DTRequest.GetQueryInt("pid");
            string ftype        = DTRequest.GetQueryString("ftype");;                            //文件类别
            bool   _isthumbnail = false;                                                         //默认不生成缩略图

            byte[] byteData = FileHelper.ConvertStreamToByteBuffer(context.Request.InputStream); //获取文件流

            if (byteData.Length == 0)
            {
                context.Response.Write("{\"status\": 0, \"msg\": \"请选择要上传文件!\"}");
                return;
            }
            if (DTRequest.GetQueryString("IsThumbnail") == "1")
            {
                _isthumbnail = true;
            }
            UpLoad upLoad = new UpLoad();

            fileName = fileName.Replace(" ", "");//去掉空格
            string msg = upLoad.PayFileSaveAs(byteData, fileName, _isthumbnail, pid, ftype);

            msg = Regex.Replace(msg, @"(\\[^bfrnt\\/'\""])", "\\$1");//利用正则表达式先把待解析的字符串中的带“\”特殊字符处理,再进行解析操作
            JObject jo = JObject.Parse(msg);

            if (jo["status"].ToString() == "1")
            {
                Model.manager manager = new ManagePage().GetAdminInfo();//获得当前登录管理员信息
                Model.payPic  file    = new Model.payPic();
                file.pp_rid           = pid;
                file.pp_type          = Utils.ObjToByte(ftype);
                file.pp_fileName      = fileName;
                file.pp_filePath      = jo["path"].ToString();
                file.pp_thumbFilePath = jo["thumb"].ToString();
                file.pp_size          = Utils.ObjToDecimal(jo["size"].ToString(), 0);
                file.pp_addDate       = DateTime.Now;
                file.pp_addName       = manager.real_name;
                file.pp_addPerson     = manager.user_name;
                new BLL.payPic().insertPayFile(file, manager);
            }
            //返回成功信息
            context.Response.Write(msg);
            context.Response.End();
        }