Пример #1
0
        /// <summary>
        /// 图片上传
        /// </summary>
        public void FileUpload()
        {
            ModJsonResult json = new ModJsonResult();
            string        str  = ""; //图片上传失败原因
            string        path = ""; //文件路径

            try
            {
                string             id         = Request["id"].ToString();
                HttpPostedFileBase ModelFile  = Request.Files["winImg" + id];
                string             filename   = ModelFile.FileName;                                                //获取上传的文件名称
                string             configPath = System.Configuration.ConfigurationManager.AppSettings["NewsPath"]; //新闻图片保存路径
                if (!string.IsNullOrEmpty(filename))
                {
                    if (new PicFileUpLoad().UpLoad("News", ModelFile, configPath, filename, out path, out str))
                    {
                        //获取图片宽度和高度
                        int width = 0; int height = 0;
                        UploadFile.GetWidthHeight(out width, out height, Server.MapPath(path));
                        json.success = true;
                        json.msg     = path;
                        json.data    = "[{width:" + width + ",height:" + height + "}]";
                    }
                    else
                    {
                        json.success = false;
                        json.msg     = str;
                    }
                }
            }
            catch (Exception a)
            {
                json.success = false;
                json.msg     = a.Message;
            }
            WriteJsonToPage(json.ToString());
        }