zoukankan      html  css  js  c++  java
  • HTML5多文件异步上传 个人笔记代码

    <html>
    
    <head>
    
    
     
    <script>
    
      var fileObjs = document.getElementById("file_upload").files;             //获取文件数量   
    
       var fileNum = fileObjs.length;
    
       var formdate = new FormData();   
    
       for (var i = 0; i < fileNum; i++) 
    
      {     
    
          formdate.append("file_upload" + i, fileObjs[i]);   
    
      }           
    
       formdate.append("fileNum", fileNum);
    
    
      $.ajax({
                    type: "POST",
                    url: "../ajax/UploadPosDateImg.ashx",
                    data: formdate,
                    cache: false,
                    processData: false,
                    contentType: false,
                    success: function (data) {
                   
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        alert("上传失败!");
                    }
                });
    
     
    </script>
     
     </head>
    
           <body> 
     <form id="form1" method="POST" enctype="multipart/form-data">
         <input type="file" name="file_upload" multiple="multiple" id="file_upload" class="file" />
     </form>
          </body>
     </thml>

     c#后端

        string filePath = "";
                var fileNum = int.Parse(HttpContext.Current.Request.Form["fileNum"]);
                if (fileNum <= 0)
                {
                    return;
                }
                for (int i = 0; i < fileNum; i++)
                {
                    HttpPostedFile file = HttpContext.Current.Request.Files["file_upload" + i];
                    filePath += (FileUpload.UpLoadImage(file, FileUploadFunctionType.POSDataImage) + ",");
                }
                if (!string.IsNullOrEmpty(filePath))
                {
                    filePath = filePath.Substring(0, filePath.Length - 1);
                }
                context.Response.Write(filePath);
  • 相关阅读:
    MYSQL中replace into的用法
    Typora自定义样式
    Advanced Installer轻松带你入门
    H2数据库入门,看这篇就对了
    Linux之vim的使用
    Linux文件上传与下载
    @ConfigurationProperties 注解使用姿势,这一篇就够了
    Javadoc 使用详解
    MySQL学习提升
    JS前端获取用户的ip地址的方法
  • 原文地址:https://www.cnblogs.com/majiabin/p/5667621.html
Copyright © 2011-2022 走看看