zoukankan      html  css  js  c++  java
  • 文件上传

    需要用FileUpload1控件:

     //Label1.Text = FileUpload1.PostedFile.ContentLength.ToString();  文件大小,单位字节
            string[] sl = FileUpload1.FileName.Split('.');
            if (sl[sl.Length - 1] == "aspx" || sl[sl.Length - 1] == "asp")     //保证文件安全 约束可上传类型
            {
                Response.Write("<script>alert('文件格式不正确')</script>");
                return;
            }
            FileUpload1.SaveAs(Server.MapPath("ul/"+DateTime.Now.ToString("yyyyMMddHHmmssms") +FileUpload1.FileName));
            //SaveAs保存文件 ,Server.MapPath返回绝对路径,文件后缀以及防止重名,ul为文件夹名称

    accept=".tet,.png"         设置用户可选择的文件格式;

    允许上传的最大文件大小4M,可以在配置文件中扩容:

    <httpRuntime maxRequestLength="409600"   />

    但并不实用;

    应该在JS中限制:

    document.getElementById("Button1").onclick = function () {                                   
            if (document.getElementById("FileUpload1").files[0].size > 1024 * 1024 * 4) {
                alert("文件太大!");
                return false;
            }
        }
  • 相关阅读:
    [NOIP2020]T2字符串匹配
    【CSGRound2】逐梦者的初心(洛谷11月月赛 II & CSG Round 2 T3)
    【CF1225E Rock Is Push】推岩石
    [HAOI2016]食物链
    求先序排列
    图书管理员
    合并果子
    联合权值
    和为0的4个值
    玩具谜题
  • 原文地址:https://www.cnblogs.com/m110/p/8282456.html
Copyright © 2011-2022 走看看