码迷,mamicode.com
首页 > Web开发 > 详细

上传图片后台写法

时间:2017-05-25 01:22:37      阅读:199      评论:0      收藏:0      [点我收藏+]

标签:turn   table   server   director   tor   info   map   图片   post   

[HttpPost]

        public ActionResult UpFile()

        {

 

 

            int count = Request.Files.Count;

 

 

            for (int i = 0; i < count; i++)

            {

                WebTest.Entity.FileInfo fileInfo = new WebTest.Entity.FileInfo();

                HttpPostedFileBase file = Request.Files[i];

                string[] NameTpye = file.FileName.Split(new char[] { ‘.‘ });

          

                string Path = "/Image/UpWord/" + DateTime.Now.ToString("yyyyMMddHHmmssffff");

                string FilePath = Server.MapPath(Path);

                if (!Directory.Exists(FilePath))

                {

                    Directory.CreateDirectory(FilePath);

                }

                file.SaveAs(FilePath + "/" + file.FileName);

 

                fileInfo.FileName = NameTpye[0];

                fileInfo.FileType = "." + NameTpye[1];

                fileInfo.FileUrl = Path + "/" + file.FileName;

                fileInfo.Refnum = 1;

                fileInfo.RefnumTable = "News";

                fileInfo.Size = (file.ContentLength / 1024).ToString();

 

                db.Set<WebTest.Entity.FileInfo>().Add(fileInfo);

 

            }

            int res = db.SaveChanges();

 

            if (res > 0)

            {

                return Content("OK:上传文件成功!");

            }

            else

            {

                return Content("NO:上传文件失败!");

            }

        }

上传图片后台写法

标签:turn   table   server   director   tor   info   map   图片   post   

原文地址:http://www.cnblogs.com/duanyuerui/p/6901642.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!