Esempio n. 1
0
        private void UpLoadFile(HttpContext context)
        {
            string _delfile = DTRequest.GetString("DelFilePath");                                    //要删除的文件
            string fileName = DTRequest.GetString("name");                                           //文件名

            byte[] byteData     = FileHelper.ConvertStreamToByteBuffer(context.Request.InputStream); //获取文件流
            bool   _iswater     = false;                                                             //默认不打水印
            bool   _isthumbnail = false;                                                             //默认不生成缩略图

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

            //删除已存在的旧文件
            if (!string.IsNullOrEmpty(_delfile))
            {
                upLoad.DeleteFile(_delfile);
            }
            //返回成功信息
            context.Response.Write(msg);
            context.Response.End();
        }
Esempio n. 2
0
        private void UpLoadFile(HttpContext context)
        {
            Model.sysconfig sysConfig = new BLL.sysconfig().loadConfig();
            //检查是否允许匿名上传

            /*if (sysConfig.fileanonymous == 0 && !new ManagePage().IsAdminLogin() && !new BasePage().IsUserLogin())
             * {
             *  context.Response.Write("{\"status\": 0, \"msg\": \"禁止匿名非法上传!\"}");
             *  return;
             * }*/

            string _delfile = DTRequest.GetString("DelFilePath");                                    //要删除的文件
            string fileName = DTRequest.GetString("name");                                           //文件名

            byte[] byteData     = FileHelper.ConvertStreamToByteBuffer(context.Request.InputStream); //获取文件流
            bool   _iswater     = false;                                                             //默认不打水印
            bool   _isthumbnail = false;                                                             //默认不生成缩略图

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

            //删除已存在的旧文件
            if (!string.IsNullOrEmpty(_delfile))
            {
                upLoad.DeleteFile(_delfile);
            }
            //返回成功信息
            context.Response.Write(msg);
            context.Response.End();
        }