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("请上传正确的图片格式");
            }
           
        }

  • 相关阅读:
    linux kernel内存碎片防治技术
    内核线程
    Linux内核高端内存
    Lcd(一)显示原理
    LSB和MSB
    图解slub
    数据库小试题2
    编写函数获取上月的最后一天
    php中的static静态变量
    mysql小试题
  • 原文地址:https://www.cnblogs.com/szytwo/p/2515358.html
Copyright © 2011-2022 走看看