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

  • 相关阅读:
    Codeforces Round#410 Div.2
    AtCoder Beginner Contest-060
    如何将gedit变成c++编译器
    洛谷 P2486 [SDOI2011]染色
    让lu哥头痛了许久的代码(洛谷:树的统计)
    字符串模拟入门
    luogu P1553 数字反转(升级版)
    那些令人难忘的——坑
    luogu P1341 无序字母对
    最短路相关题目
  • 原文地址:https://www.cnblogs.com/szytwo/p/2515358.html
Copyright © 2011-2022 走看看