///<summary>
        ///上传用户个人中心背景。
        ///</summary>
        private void UploadUserCenterBg(HttpContext context)
        {
            string tel = context.Request.Form["tel"].ToString();
            string filename = context.Request.Form["filename"].ToString();
            filename = Path.GetFileName(filename);
            string dirPath = HttpContext.Current.Server.MapPath("~/UploadFile/UserCenterBg/");
            //string fileName = DateTime.Now.ToString("yyyyMMddHHmmssffff") + ".png";
            string filePath = dirPath + filename;//file.FileName;
            #region  2015-11-2  刘
            if (!Directory.Exists(dirPath))
            {
                Directory.CreateDirectory(dirPath);
            }
            #endregion

            BLL.user_tb ubll = new BLL.user_tb();
            Model.user_tb u = ubll.GetModel(tel);
            u.personcenter_bg = "/UploadFile/UserCenterBg/" + filename;
            ubll.Update(u);

            string Pic_Path = filePath;
            try
            {
                HttpFileCollection files = context.Request.Files;
                HttpPostedFile file = context.Request.Files[0];
                file.SaveAs(Pic_Path);

            }
            catch (Exception ex)
            {
                context.Response.Write("{\"retStatus\":0,\"Msg\":\"" + ex.Message + "\",\"data\":{}}");
            }
            string result = "{\"Status\":\"success\",\"Msg\":\"上传成功\",\"data\":\"" + "\"}";
            context.Response.Write(result);
        }
 /// <summary>
 /// 上传用户头像。
 /// </summary>
 private void UploadHeadPhoto(HttpContext context)
 {
     string dirPath = context.Server.MapPath("~/UploadFile/HeadPhoto/");
     string tel = context.Request.Form["tel"].ToString();
     if (!Directory.Exists(dirPath))
     {
         Directory.CreateDirectory(dirPath);
     }
     try
     {
         HttpFileCollection files = context.Request.Files;
         if (files.Count > 0)
         {
             for (int i = 0; i < files.Count; i++)
             {
                 HttpPostedFile file = context.Request.Files[i];
                 string fileName = DateTime.Now.ToString("yyyyMMddHHmmssffff") + ".jpg";
                 string filePath = dirPath + fileName;//file.FileName;
                 file.SaveAs(filePath);
                 DataServer.Util.MakeThumbnail(filePath, dirPath + "thumbHeadPhoto/thumb_" + fileName, 160, 120, "HW", "jpg");
                 BLL.user_tb ubll = new BLL.user_tb();
                 Model.user_tb u = ubll.GetModel(tel);
                 u.user_photo = "/UploadFile/HeadPhoto/" + fileName;
                 ubll.Update(u);
             }
         }
         string result = "{\"Status\":\"success\",\"Msg\":\"上传成功\",\"data\":{}}";
         context.Response.Write(result);
     }
     catch (Exception e)
     {
         string result = "{\"Status\":\"faild\",\"Msg\":\"上传失败," + e.Message + "\",\"data\":{}}";
     }
 }
        /// <summary>
        /// 上传用户头像base64编码形式。
        /// liu
        /// </summary>
        private void UploadHeadPhoto0(HttpContext context)
        {
            string tel = context.Request.Form["tel"].ToString();
            string base64 = context.Request.Form["base64"].ToString();

            string dirPath = HttpContext.Current.Server.MapPath("~/UploadFile/HeadPhoto/");
            string fileName = DateTime.Now.ToString("yyyyMMddHHmmssffff") + ".png";
            string filePath = dirPath + fileName;//file.FileName;

            if (!Directory.Exists(dirPath))
            {
                Directory.CreateDirectory(dirPath);
            }

            BLL.user_tb ubll = new BLL.user_tb();
            Model.user_tb u = ubll.GetModel(tel);
            u.user_photo = "/UploadFile/HeadPhoto/" + fileName;
            ubll.Update(u);

            string Pic_Path = filePath;
            try
            {
                using (FileStream fs = new FileStream(Pic_Path, FileMode.Create))
                {
                    using (BinaryWriter bw = new BinaryWriter(fs))
                    {
                        byte[] data = Convert.FromBase64String(base64);
                        bw.Write(data);
                        bw.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                context.Response.Write("{\"retStatus\":0,\"Msg\":\"" + ex.Message + "\",\"data\":{}}");
            }

            string result = "{\"Status\":\"success\",\"Msg\":\"上传成功\",\"data\":\"" + u.user_photo + "\"}";
            context.Response.Write(result);
        }
Exemple #4
0
        public string uploadHeadPhoto(string tel, string imgData)
        {
            //HttpPostedFile file = context.Request.Files[i];
            string dirPath = HttpContext.Current.Server.MapPath("~/UploadFile/HeadPhoto/");
            string fileName = DateTime.Now.ToString("yyyyMMddHHmmssffff") + ".png";
            string filePath = dirPath + fileName;//file.FileName;

            BLL.user_tb ubll = new BLL.user_tb();
            Model.user_tb u = ubll.GetModel(tel);
            u.user_photo = "/UploadFile/HeadPhoto/" + fileName;
            ubll.Update(u);

            string Pic_Path = filePath;
            // imgData = imgData.Replace("%2B", "+");
            try
            {
                using (FileStream fs = new FileStream(Pic_Path, FileMode.Create))
                {
                    using (BinaryWriter bw = new BinaryWriter(fs))
                    {
                        byte[] data = Convert.FromBase64String(imgData);
                        bw.Write(data);
                        bw.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                return "{\"retStatus\":0,\"Msg\":\"" + ex.Message + "\",\"data\":{}}";
            }

            string result = "{\"Status\":\"success\",\"Msg\":\"上传成功\",\"data\":{}}";
            return result;
        }