如何上传图片

public ActionResult AddPicture(string image1, string UserID, string oldIcon)

        {

            string UserIDs = DESEncrypt.Decrypt(UserID) == "" ? "0" : DESEncrypt.Decrypt(UserID);//ID

            //string UserIDs = UserID;

            string HeadPortraitpicture = "";//头像

 

            //校验参数是否为空

            string arReString = myConvertHelper.CheckParameterIsNullstr(new Dictionary<string, object> {

                  {"用户ID",UserIDs}

            });

            //参数为空则不执行查询方法

            if (arReString != null)

            {

                return Json(arReString, JsonRequestBehavior.AllowGet);

            }

            HeadPortraitpicture = Base64StringToImageReleaseNeed(image1);

 

            int ListReturn = 0;

            try

            {

                ListReturn = DALMethod.intChaXunShuJu("ZhuXiuJuanAPI_Manage", new Dictionary<string, object> {

                    {"@UserID", UserIDs },

                    {"@HeadPortrait", HeadPortraitpicture},

                    {"@Type","UpadteHeadPortrait" }

                });

                if (ListReturn >= 1)

                {

                    List<Dictionary<string, object>> ListReturn2 = new List<Dictionary<string, object>>();

                    ListReturn2 = DALMethod.ListChaXunShuJu("ZhuXiuJuanAPI_Manage", new Dictionary<string, object> {

                   { "@Type","SelectHeadPortrait" }, {"@UserID",UserIDs } });

                    RS.result = 200;

                    RS.data = ListReturn2;

                    RS.message = "更换头像成功";

 

                    //修改成功后才,删除旧的图片

                    if (oldIcon != "" && oldIcon != null)

                    {

                        try

                        {

                            //获取路径中的图片

                            HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(oldIcon);

                            string url = req.Address.LocalPath;//截取存在的路径

                            string Split = url.Substring(0, url.Length - 1);//除去/

                            if (Split != null && Split != "")

                            {

                                string opath = Server.MapPath("~") + url;

                                //删除文件

                                if (System.IO.File.Exists(opath))

                                {

                                    System.IO.File.Delete(opath);

                                }

                            }

                        }

                        catch

                        {  //异常不用处理了人家需要,我有什么办法,

                        }

                    }

                    return Json(RS, JsonRequestBehavior.AllowGet);

                }

                else

                {

                    RS.result = 201;

                    RS.message = "更换头像失败";

                    return Json(RS, JsonRequestBehavior.AllowGet);

                }

            }

            catch (Exception e)

            {

                RS.result = 500;

                RS.message = e.ToString();

                return Json(RS, JsonRequestBehavior.AllowGet);

            }

        }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值