标签数组上传图片,后台根据Request.Files["img"]来接收前台上传的图片。">
    PHP群:95885625 Hbuilder+MUI群:81989597 站长QQ:634381967
    您现在的位置: 首页 > 开发编程 > ASP.NET教程 > 正文

    Asp.net mvc上传多张图片后台存储

    作者:admin来源:网络浏览:时间:2020-09-30 00:07:50我要评论
    导读:Asp.net mvc上传多张图片后台存储,前台页面通过标签数组上传图片,后台根据Request.Files["img"]来接收前台上传的图片。
    前台页面通过<file name="img">标签数组上传图片,后台根据Request.Files["img"]来接收前台上传的图片。
    System.Web.HttpFileCollection files = System.Web.HttpContext.Current.Request.Files;
                if (files.Count == 0)
                    return false;
                for (int i = 0; i < files.AllKeys.Count(); i++)
                {
                    if (files.AllKeys[i] != "img")
                    {
                        if (files[i].FileName.Length > 0)
                        {
                            System.Web.HttpPostedFile postedfile = files[i];
                            string filePath = "";
                            var ext = Path.GetExtension(postedfile.FileName);
                            var fileName = DateTime.Now.Ticks.ToString() + ext;
                            // 组合文件存储的相对路径 www.bcty365.com
                            filePath = "/Upload/images/" + fileName;
                            // 将相对路径转换成物理路径
                            var path = Server.MapPath(filePath);
                            postedfile.SaveAs(path);
                            string fex = Path.GetExtension(postedfile.FileName);
                            //存储产品轮播图信息
                            ProductCarousel model = new ProductCarousel();
                            model.ProductID = productID;
                            model.PicSlider = filePath;
                            db.ProductCarousels.Add(model);
                            db.SaveChanges();
                        }
                    }
                    
                }
    转载请注明(B5教程网)原文链接:https://b5.mxunkeji.com/content-11-3253-1.html
    相关热词搜索: