Example #1
0
        /// <summary>
        ///  兼容 ProductImgTest    tag用于排序
        /// </summary>
        /// <param name="targetid"></param>
        /// <param name="registerid"></param>
        /// <param name="tp"></param>
        /// <param name="fname"></param>
        /// <param name="rdm"></param>
        /// <param name="tag"></param>
        /// <returns></returns>
        public ActionResult UploadImage(int targetid, int registerid, int tp, string fname, string rdm, int tag)
        {
            HttpFileCollection hfc          = System.Web.HttpContext.Current.Request.Files;
            string             imgPath      = "";
            string             PhysicalPath = "";
            string             json         = "{\"ret\":0,\"msg\":\"上传图片失败!\"}";
            string             path2        = "/ProductImg/UploadFiles/";
            string             fileName     = "";

            if (hfc.Count > 0)
            {
                var    httpfile = hfc[0];
                string suf      = "";
                if (!isImage(httpfile.FileName, out suf))
                {
                    json = "{\"ret\":0,\"msg\":\"图片只支持---gif|jpg|jpeg|bmp!\"}";
                    return(Content(json, "text/json"));
                }
                fileName = string.Format("{0}.{1}", sjname() + rdm, suf);
                imgPath  = @"/ProductImg/UploadFiles/";
                var ss = httpfile.ContentType;
                PhysicalPath = Server.MapPath(imgPath);
                if (!System.IO.Directory.Exists(PhysicalPath))
                {
                    System.IO.Directory.CreateDirectory(PhysicalPath);
                }

                PhysicalPath = PhysicalPath + fileName;
                httpfile.SaveAs(PhysicalPath);



                imgPath = imgPath + fileName;

                if (Utils.CheckPictureSafe(PhysicalPath))
                {
                    if (!string.IsNullOrEmpty(imgPath))
                    {
                        hx_borrower_guarantor_picture p = new hx_borrower_guarantor_picture();
                        p.targetid            = targetid;
                        p.borrower_registerid = registerid;
                        p.picture_name        = Utils.CheckSQLHtml(fname);
                        p.type_picture        = tp;
                        p.picture_index       = tag;
                        p.picture_path        = path2 + fileName;
                        p.uploadtime          = DateTime.Now;
                        ef.hx_borrower_guarantor_picture.Add(p);
                        ef.SaveChanges();

                        imgPath = imgPath.Replace("/", "//");
                        json    = "{\"ret\":1,\"path\":\"" + imgPath + "\",\"key\":" + p.borrower_guarantor_picture_id + "}";
                    }
                }
                else
                {   //图片安全提醒,您试除上传非法文件
                    json = "{\"ret\":0,\"path\":\"图片中含有非法文件\"}";
                }
            }
            return(Content(json, "text/json"));
        }
Example #2
0
        /// <summary>
        /// 基础材料
        /// </summary>
        /// <returns></returns>
        public ActionResult ProductImg(int targetid, int registerid, int tp)
        {
            string             savePath    = Server.MapPath("\\ProductImg\\UploadFiles") + "\\";//上传文件保存路径
            string             path2       = "/ProductImg/UploadFiles/";
            string             files       = Request["UploadFile"];
            HttpFileCollection uploadFiles = System.Web.HttpContext.Current.Request.Files;

            string filename1 = DNTRequest.GetString("filename");

            string[] strArray = filename1.Split(new char[] { ',' });
            string   filename;//文件名字
            string   json = "{\"ret\":0,\"msg\":\"上传图片失败!\"}";

            string PhysicalPath = "";

            for (int i = 0; i < uploadFiles.Count; i++)
            {
                if (uploadFiles[i].FileName != "")
                {
                    filename = uploadFiles[i].FileName;
                    string suf = "";
                    if (!isImage(filename, out suf))
                    {
                        json = "{\"ret\":0,\"msg\":\"图片只支持---gif|jpg|jpeg|bmp!\"}";
                        return(Content(json, "text/json"));
                    }
                    string newfileName = string.Format("{0}.{1}", sjname(), suf);

                    if (!System.IO.Directory.Exists(savePath))
                    {
                        System.IO.Directory.CreateDirectory(savePath);
                    }
                    PhysicalPath = savePath + newfileName;

                    uploadFiles[i].SaveAs(PhysicalPath);

                    if (Utils.CheckPictureSafe(PhysicalPath))
                    {
                        hx_borrower_guarantor_picture p = new hx_borrower_guarantor_picture();
                        p.targetid            = targetid;
                        p.borrower_registerid = registerid;
                        p.picture_name        = Utils.CheckSQLHtml(strArray[i].ToString());
                        p.type_picture        = tp;
                        p.picture_path        = path2 + newfileName;
                        p.uploadtime          = DateTime.Now;
                        ef.hx_borrower_guarantor_picture.Add(p);
                        ef.SaveChanges();

                        json = "{\"ret\":1,\"msg\":\"上传成功!\"}";
                    }
                    else
                    {   //图片安全提醒,您试除上传非法文件
                        json = "{\"ret\":0,\"path\":\"图片中含有非法文件\"}";
                        return(Content(json, "text/json"));
                    }
                }
            }
            return(Content(json, "text/json"));
        }