예제 #1
0
 private void EditorFile(HttpContext context)
 {
     bool _iswater = false; //默认不打水印
     if (context.Request.QueryString["IsWater"] == "1")
         _iswater = true;
     HttpPostedFile imgFile = context.Request.Files["imgFile"];
     if (imgFile == null)
     {
         showError(context, "请选择要上传文件!");
         return;
     }
     UpLoad upFiles = new UpLoad();
     string remsg = upFiles.fileSaveAs(imgFile, false, _iswater);
     JsonData jd = JsonMapper.ToObject(remsg);
     string status = jd["status"].ToString();
     string msg = jd["msg"].ToString();
     if (status == "0")
     {
         showError(context, msg);
         return;
     }
     string filePath = jd["path"].ToString(); //取得上传后的路径
     Hashtable hash = new Hashtable();
     hash["error"] = 0;
     hash["url"] = filePath;
     context.Response.AddHeader("Content-Type", "text/html; charset=UTF-8");
     context.Response.Write(JsonMapper.ToJson(hash));
     context.Response.End();
 }
예제 #2
0
        private void UpLoadFile(HttpContext context)
        {
            string _delfile = MXRequest.GetString("DelFilePath");
            HttpPostedFile _upfile = context.Request.Files["Filedata"];
            bool _iswater = false; //默认不打水印
            bool _isthumbnail = false; //默认不生成缩略图

            if (MXRequest.GetQueryString("IsWater") == "1")
                _iswater = true;
            if (MXRequest.GetQueryString("IsThumbnail") == "1")
                _isthumbnail = true;
            if (_upfile == null)
            {
                context.Response.Write("{\"status\": 0, \"msg\": \"请选择要上传文件!\"}");
                return;
            }
            UpLoad upFiles = new UpLoad();
            string msg = upFiles.fileSaveAs(_upfile, _isthumbnail, _iswater);
            //删除已存在的旧文件
            if (!string.IsNullOrEmpty(_delfile))
            {
                Utils.DeleteUpFile(_delfile);
            }
            //返回成功信息
            context.Response.Write(msg);
            context.Response.End();
        }