zoukankan      html  css  js  c++  java
  • ASP.NET中FileUpload中的代码怎么编写?

    protected void submit_Click(object sender, EventArgs e)
        {
            string name = FileUpload1.FileName;
            int size = FileUpload1.PostedFile.ContentLength;
            string type = FileUpload1.PostedFile.ContentType;             //image/pjpeg
            // string type2 = name.Substring(name.LastIndexOf(".") + 1);     //jpg 不安全
            string ipath = Server.MapPath(@"~\img\") + name;
            string dpath = @"~\img\" + name;
            if (type.Contains("image"))
            {
                if (size < 1048576)    // 1MB
                {
                    FileUpload1.SaveAs(ipath);
                    Image1.Visible = true;
                    Image1.ImageUrl = dpath;
                    Response.Write("恭喜你上传成功!");
                }
                else
                {
                    Response.Write("图片过大!请上传小于1MB的图片");
                }
            }
            else
            {
                Response.Write("请上传正确的图片格式");
            }
           
        }

  • 相关阅读:
    维护
    zabbix监控线
    java——快排、冒泡、希尔、归并
    java——注解处理器
    spring boot——常用注解
    java——修改txt文件中某一行的内容
    spring boot——关于一个Mysql主键的问题
    mysql
    springboot
    自信点,不要怕
  • 原文地址:https://www.cnblogs.com/szytwo/p/2515358.html
Copyright © 2011-2022 走看看