コード例 #1
0
ファイル: NewsReleaseController.cs プロジェクト: dmhai/dxpay
        public JsonResult UploadImg()
        {
            //回传图片路径
            string returnurl        = string.Empty;
            string msg              = string.Empty;
            string tag              = "0";
            NameValueCollection nvc = System.Web.HttpContext.Current.Request.Form;
            HttpFileCollection  hfc = System.Web.HttpContext.Current.Request.Files;

            string[] result = { null, null };
            if (hfc.Count == 1)
            {
                if (hfc[0].ContentLength > (1024 * 1024 * 2))
                {
                    return(Json(new { mess = "图片大小不能超过2M", success = "0" }, "text/html", JsonRequestBehavior.AllowGet));
                }
                else
                {
                    string purl = nvc["purl"];
                    try
                    {
                        purl = purl.StartsWith("B") ? purl.TrimStart('B') : purl.StartsWith("A") ? purl.TrimStart('A') : purl;
                        if (!string.IsNullOrEmpty(purl))
                        {
                            PubImageUp.DeleteImage(purl);
                        }
                    }
                    catch (Exception e)
                    {
                    }
                    //获取配置文件里的上传路径
                    string uploadurl = ConfigurationManager.AppSettings["newuploadurl"];
                    result = PubImageUp.UpnewImages("certificatefile", uploadurl);
                    if (result.Length == 2)
                    {
                        if (result[0] != "99")
                        {
                            returnurl = result[1];
                        }
                        else
                        {
                            msg = result[1];
                        }
                        tag = "1";
                    }
                }
            }

            return(Json(
                       new
            {
                Id = nvc["tid"],
                name = nvc["tname"],
                imgurl = returnurl,
                mess = msg,
                success = tag
            }, "text/html", JsonRequestBehavior.AllowGet));
        }
コード例 #2
0
      public JsonResult UploadImgxkz()
      {
          //回传图片路径
          string returnurl = string.Empty;
          //用于回传显示地址
          string returnurl2       = string.Empty;
          string msg              = string.Empty;
          string tag              = "0";
          NameValueCollection nvc = System.Web.HttpContext.Current.Request.Form;
          HttpFileCollection  hfc = System.Web.HttpContext.Current.Request.Files;

          string[] result = { null, null };
          if (hfc.Count == 1)
          {
              if (hfc[0].ContentLength > (1024 * 1024 * 2))
              {
                  return(Json(new { mess = "图片大小不能超过2M", success = "0" }, "text/html", JsonRequestBehavior.AllowGet));
              }
              else
              {
                  string purl = nvc["purl"];
                  try
                  {
                      if (!string.IsNullOrEmpty(purl))
                      {
                          PubImageUp.DeleteImage(purl);
                      }
                  }
                  catch (Exception e)
                  {
                  }
                  //获取配置文件里的上传路径
                  string uploadurl = ConfigurationManager.AppSettings["uploadurlkfz"] + "/kfz_img/";
                  //图片域名地址
                  string imgurlroot = ConfigurationManager.AppSettings["imgurl"] + "/kfz_img/";
                  //上传图片
                  result = PubImageUp.UpImages("licencefilef", uploadurl);
                  //图片返回展示地址
                  returnurl2 = imgurlroot + result[0];
                  if (result.Length == 2)
                  {
                      if (result[0] != "99")
                      {
                          returnurl = "/kfz_img/" + result[0];
                      }

                      else
                      {
                          msg = "/kfz_img/" + result[0];
                      }

                      tag = "1";
                  }
              }
          }

          return(Json(
                     new
            {
                Id = nvc["tid"],
                name = nvc["tname"],
                imgurl = returnurl,
                imgurlroot = returnurl2,
                mess = msg,
                success = tag
            }, "text/html", JsonRequestBehavior.AllowGet));
      }