private void SingleFile(HttpContext context)
        {
            string _refilepath = context.Request.QueryString["ReFilePath"]; //取得返回的对象名称
            string _upfilepath = context.Request.QueryString["UpFilePath"]; //取得上传的对象名称
            string _delfile = context.Request.Params[_refilepath];
            HttpPostedFile _upfile = context.Request.Files[_upfilepath];
            bool _iswater = false; //默认不打水印
            bool _isthumbnail = false; //默认不生成缩略图

            if (context.Request.QueryString["IsWater"] == "1")
                _iswater = true;
            if (context.Request.QueryString["IsThumbnail"] == "1")
                _isthumbnail = true;

            if (_upfile == null)
            {
                context.Response.Write("{msg: 0, msbox: \"请选择要上传文件!\"}");
                return;
            }
            UpLoad upFiles = new UpLoad();
            string msg = upFiles.fileSaveAs(_upfile, _isthumbnail, _iswater);
            //删除已存在的旧文件
            Utils.DeleteUpFile(_delfile);
            //返回成功信息
            context.Response.Write(msg);
            context.Response.End();
        }
示例#2
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);
     Dictionary<string, object> dic = JsonHelper.DataRowFromJSON(remsg);
     string status = dic["status"].ToString();
     string msg = dic["msg"].ToString();
     if (status == "0")
     {
         showError(context, msg);
         return;
     }
     string filePath = dic["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(JsonHelper.ObjectToJSON(hash));
     context.Response.End();
 }
示例#3
0
        private void UpLoadFile(HttpContext context)
        {
            Model.siteconfig siteConfig = new BLL.siteconfig().loadConfig();
            string _delfile = DTRequest.GetString("DelFilePath");
            HttpPostedFile _upfile = context.Request.Files["Filedata"];
            bool _iswater = false; //默认不打水印
            bool _isthumbnail = false; //默认不生成缩略图

            if (DTRequest.GetQueryString("IsWater") == "1")
                _iswater = true;
            if (DTRequest.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) && _delfile.IndexOf("../") == -1 
                && _delfile.ToLower().StartsWith(siteConfig.webpath.ToLower() + siteConfig.filepath.ToLower()))
            {
                Utils.DeleteUpFile(_delfile);
            }
            //返回成功信息
            context.Response.Write(msg);
            context.Response.End();
        }
示例#4
0
        private void AttachFile(HttpContext context)
        {
            string _upfilepath = context.Request.QueryString["UpFilePath"]; //取得上传的对象名称
            HttpPostedFile _upfile = context.Request.Files[_upfilepath];
            bool _iswater = false; //默认不打水印
            bool _isthumbnail = false; //默认不生成缩略图

            if (_upfile == null)
            {
                context.Response.Write("{\"msg\": 0, \"msgbox\": \"请选择要上传文件!\"}");
                return;
            }
            UpLoad upFiles = new UpLoad();
            string msg = upFiles.fileSaveAs(_upfile, _isthumbnail, _iswater, false, true);
            //返回成功信息
            context.Response.Write(msg);
            context.Response.End();
        }
示例#5
0
        private void user_avatar_crop(HttpContext context)
        {
            //检查用户是否登录
            Model.users model = new BasePage().GetUserInfo();
            if (model == null)
            {
                context.Response.Write("{\"msg\":0, \"msgbox\":\"对不起,用户没有登录或登录超时啦!\"}");
                return;
            }
            string fileName = DTRequest.GetFormString("hideFileName");
            int x1 = DTRequest.GetFormInt("hideX1");
            int y1 = DTRequest.GetFormInt("hideY1");
            int w = DTRequest.GetFormInt("hideWidth");
            int h = DTRequest.GetFormInt("hideHeight");
            //检查是否图片

            //检查参数
            if (!Utils.FileExists(fileName) || w == 0 || h == 0)
            {
                context.Response.Write("{\"msg\":0, \"msgbox\":\"对不起,请先上传一张图片!\"}");
                return;
            }
            //取得保存的新文件名
            UpLoad upFiles = new UpLoad();
            bool result = upFiles.cropSaveAs(fileName, fileName, 180, 180, w, h, x1, y1);
            if (!result)
            {
                context.Response.Write("{\"msg\": 0, \"msgbox\": \"图片裁剪过程中发生意外错误!\"}");
                return;
            }
            //删除原用户头像
            Utils.DeleteFile(model.avatar);
            model.avatar = fileName;
            //修改用户头像
            new BLL.users().UpdateField(model.id, "avatar='" + model.avatar + "'");
            context.Response.Write("{\"msg\": 1, \"msgbox\": \"" + model.avatar + "\"}");
            return;
        }
示例#6
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);
     //string pattern = @"^{\s*msg:\s*(.*)\s*,\s*msgbox:\s*\""(.*)\""\s*}$"; //键名前和键值前后都允许出现空白字符
     //Regex r = new Regex(pattern, RegexOptions.IgnoreCase); //正则表达式实例,不区分大小写
     //Match m = r.Match(remsg); //搜索匹配项
     //string msg = m.Groups[1].Value; //msg的值,正则表达式中第1个圆括号捕获的值
     //string msgbox = m.Groups[2].Value; //msgbox的值,正则表达式中第2个圆括号捕获的值
     JsonData jd = JsonMapper.ToObject(remsg);
     string msg = jd["msg"].ToString();
     string msgbox = jd["msgbox"].ToString();
     if (msg == "0")
     {
         showError(context, msgbox);
         return;
     }
     Hashtable hash = new Hashtable();
     hash["error"] = 0;
     hash["url"] = msgbox;
     context.Response.AddHeader("Content-Type", "text/html; charset=UTF-8");
     context.Response.Write(JsonMapper.ToJson(hash));
     context.Response.End();
 }
示例#7
0
        private void SingleFile(HttpContext context)
        {
            string _refilepath = DTRequest.GetQueryString("ReFilePath"); //取得返回的对象名称
            string _upfilepath = DTRequest.GetQueryString("UpFilePath"); //取得上传的对象名称
            string _delfile = DTRequest.GetString(_refilepath);
            HttpPostedFile _upfile = context.Request.Files[_upfilepath];
            bool _iswater = false; //默认不打水印
            bool _isthumbnail = false; //默认不生成缩略图
            bool _isimage = false; //默认不限制图片上传

            if (DTRequest.GetQueryString("IsWater") == "1")
                _iswater = true;
            if (DTRequest.GetQueryString("IsThumbnail") == "1")
                _isthumbnail = true;
            if (DTRequest.GetQueryString("IsImage") == "1")
                _isimage = true;

            if (_upfile == null)
            {
                context.Response.Write("{\"msg\": 0, \"msgbox\": \"请选择要上传文件!\"}");
                return;
            }
            UpLoad upFiles = new UpLoad();
            string msg = upFiles.fileSaveAs(_upfile, _isthumbnail, _iswater, _isimage);
            //删除已存在的旧文件
            Utils.DeleteUpFile(_delfile);
            //返回成功信息
            context.Response.Write(msg);
            context.Response.End();
        }
示例#8
0
        private void UpLoadFile(HttpContext context)
        {
            string _delfile = DTRequest.GetString("DelFilePath");
            HttpPostedFile _upfile = context.Request.Files["Filedata"];
            bool _iswater = false; //默认不打水印
            bool _isthumbnail = false; //默认不生成缩略图

            if (DTRequest.GetQueryString("IsWater") == "1")
                _iswater = true;
            if (DTRequest.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();
        }