码迷,mamicode.com
首页 > Web开发 > 详细

HTML5多文件异步上传 个人笔记代码

时间:2016-07-13 22:08:09      阅读:189      评论:0      收藏:0      [点我收藏+]

标签:

<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);

 

HTML5多文件异步上传 个人笔记代码

标签:

原文地址:http://www.cnblogs.com/majiabin/p/5667621.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!