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

  • 相关阅读:
    嵊州D1T2 圣女
    嵊州D1T1 总统先生,一路走好!
    第三节暑期信息奥赛课——图论
    并查集小结
    洛谷P1003 铺地毯 noip2011提高组day1T1
    洛谷p1216 IOI1994 Day1T1
    Title
    Title
    Title
    Title
  • 原文地址:https://www.cnblogs.com/szytwo/p/2515358.html
Copyright © 2011-2022 走看看