• 表单提交文件


    代码
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        
    <title>无标题页</title>
        
    <script type="text/javascript">
        
    function upfile() {
        
    var form = document.dform;
        
    // check the filename first
        var file = document.getElementById("ifile").value;
        
    var pos = file.lastIndexOf('.');
        
    var ext = file.substring(pos + 1).toLowerCase();
        
    if (ext != 'jpg' && ext != 'gif' && ext != 'png')
        {
            alert(
    '错误:您选择上传必须是 jpg/gif/png 文件!');
            
    return;
        }
        
    // replace form options
        var action = form.action;
        
    var enctype = form.enctype;
        
    var target = form.target;
        form.action 
    ="default3.aspx";
        form.enctype 
    = 'multipart/form-data';
        
    if (typeof form.encoding != 'undefined') form.encoding = 'multipart/form-data';
        form.submit();
        }
        
    </script>
    </head>
    <body>
        
    <form id="dform" name="dform"  method="post"  runat="Server">
        
    <div>
            
    <input id="ifile" name="ifile"  type="file"  onchange="upfile()"  />
            
    </div>
        
    </form>
    </body>
    </html>
    代码
        protected void Page_Load(object sender, EventArgs e)
        {
            
    if (Request.Files.Count > 0)
            {
                
    string path = Server.MapPath("uploadfile/");
                HttpPostedFile postfile 
    = Request.Files[0];
                
    if (postfile.ContentLength > 0)
                {
                    
    string name = DateTime.Now.ToString("yyMMddHHmmssfff"+ postfile.FileName;
                    postfile.SaveAs(path 
    + name);
                    Page.ClientScript.RegisterStartupScript(
    this.GetType(), "js""<script>printimage('uploadfile/" + name + "')</script>");
                }
            }
        }
  • 相关阅读:
    Binder机制,从Java到C (大纲)
    大陆台湾计算机术语比对
    关于nginx架构探究(2)
    关于nginx架构探究(1)
    关于开源中文搜索引擎架构coreseek中算法详解
    关于linux定时操作cron的理解
    sqlachemy 使用实例
    nginx+uwsgi+flask搭建python-web应用程序
    VC维
    关于zMPLS的设计解析
  • 原文地址:https://www.cnblogs.com/bobofsj11/p/1829348.html
Copyright © 2020-2023  润新知