zoukankan      html  css  js  c++  java
  • 表单提交文件

    代码
    <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>");
                }
            }
        }
  • 相关阅读:
    Shell之sed用法 转滴
    再议mysql 主从配置
    CentOS 如何将.deb 文件 转换.rpm
    scp命令[转]
    安装samba服务器
    xdebug影响php运行速度
    PHP中VC6、VC9、TS、NTS版本的区别与用法详解
    将Centos的yum源更换为国内的阿里云源
    centos网卡错误Device eth0 does not seem to be present
    虚拟机VirtualBox中centos6.5网络设置
  • 原文地址:https://www.cnblogs.com/bobofsj11/p/1829348.html
Copyright © 2011-2022 走看看