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";//默认的图片;
                }

  • 相关阅读:
    小程序开发过程中遇到的问题
    Windows 常用命令与快捷键
    前端开发中遇到的问题记录
    判断当前页面是否在微信中
    js学习导图
    一篇不错的 文章
    flex 布局
    微信客户端sdk使用前的 授权签名
    elementUI+vue-cli el-table=》excel
    rem适配
  • 原文地址:https://www.cnblogs.com/guozefeng/p/3280796.html
Copyright © 2011-2022 走看看