zoukankan      html  css  js  c++  java
  • 上传图片后台写法

    [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:上传文件失败!");

                }

            }

    NET新手,希望各位大侠多多指教。
  • 相关阅读:
    【excel】=EXACT(A1,B1) 比较两个字符串是否相等
    【oracle】oracle11g安装失败 提示找不到文件,模板General_Purpose.dbc不存在
    【oracle】11g服务器安装详细步骤
    【oracle】ceil函数 返回值 (大于参数的最小整数)
    【oracle】 months_between(date1,date2)
    javaWeb遍历获取session中的值
    tomcat+mysql数据库连接池的操作
    java中值得类型转化
    javaWeb图片验证码代码
    JSP与Servlet之间传值
  • 原文地址:https://www.cnblogs.com/duanyuerui/p/6901642.html
Copyright © 2011-2022 走看看