zoukankan      html  css  js  c++  java
  • asp.net mvc上传图片案例

     1.放在ajax.BeginForm里,不好使,同asp.net 表单中 fileupload控件不支持ajax差不多吧,如果异步的话可以借助jquery.form.js,很方便

    2.

      //上传文件
                object fielLogoImg = Request.Files["fielLogoImg"];
                if (fielLogoImg != null)
                {
                    string fileExtension = string.Empty;
                    string filename = string.Empty; ;
                    string filePathName = string.Empty;
                    if (Request.Files["fielLogoImg"].ContentLength > 0 && Request.Files["fielLogoImg"].ContentLength <= 51200)
                    {
                        bool fileJudge = false;
                        string path = Server.MapPath(Framework.Configuration.UserFilePath + CurrentUser.UName);
                        string uploadFileName = Path.GetFileName(Request.Files["fielLogoImg"].FileName);
                        fileExtension = System.IO.Path.GetExtension(Request.Files["fielLogoImg"].FileName).ToLower();
                        filename = "Logo" + fileExtension;
                        string[] ae = { ".gif", ".bmp", ".jpg", ".jpeg", ".png", ".tif" };
                        for (int i = 0; i < ae.Length; i++)
                        {
                            if (fileExtension == ae[i])
                            {
                                fileJudge = true;
                            }
                        }
                        if (fileJudge)
                        {
                            filePathName = Path.Combine(path, filename);
                            Request.Files["fielLogoImg"].SaveAs(filePathName);
                            cvModel.LogUrl = "/../Files/Web/" + CurrentUser.UName + "/" + filename;
                        }
                        else
                        {
                            return Content("提示1:上传图片类型限制:" + ".gif|.bmp|.jpg|.jpeg|.png|.tif");
                        }
                    }
                    else
                    {
                        return Content("提示4:图片大小不超过100kb");
                    }
                }
                else
                {
                    cvModel.LogUrl = "/../Files/Common/Web/Web1/Logo.png";//默认的图片;
                }

  • 相关阅读:
    HDU-2018中国大学生程序设计竞赛-网络选拔赛-1004-Find Integer
    最短路径--Floyd、Dijkstra、Bellman、SPFA算法
    最小生成树--Prim算法和Kruskal算法
    【原创】KMP算法详解
    MySQL 常见问题
    Gym 101652P:Fear Factoring 数论
    POJ 1426 Find The Multiple(kuangbin搜索专题)
    并查集(Union Find)的实现及代码应用
    SDUT 3403 数据结构实验之排序六:希尔排序
    SDUT 3402 数据结构实验之排序五:归并求逆序数
  • 原文地址:https://www.cnblogs.com/guozefeng/p/3280796.html
Copyright © 2011-2022 走看看