如何使用jquery或JavaScript在一次浏览中上传多个文件

我正在开发一个Web应用程序,我在其中为多个文件创建了一个页面
上传一次浏览而不是一次上传一个文件.

用户可以在点击浏览时选择多个文件.

如果有人有解决方案请欢迎

谢谢!

解决方法

对于替代解决方案,您可以使用HTML5多重上传,

HTML

为输入文件设置属性倍数,请检查此链接https://developer.mozilla.org/en-US/docs/Web/API/Input.multiple

<form id="form-upload">
    <input type="file" name="upload" id="upload" multiple>
</form>

JS

要使用juery上传文件,您可以使用form-data:https://developer.mozilla.org/en-US/docs/Web/Guide/Using_FormData_Objects

$('#upload').bind("change",function(){
    var formData = new FormData($("#form-upload")[0]);
    //loop for add $_FILES["upload"+i] to formData
    for (var i = 0,len = document.getElementById('upload').files.length; i < len; i++) {
        formData.append("upload"+(i+1),document.getElementById('upload').files[i]);
    }

    //send formData to server-side
    $.ajax({
        url : "process_upload.PHP",type : 'post',data : formData,dataType : 'json',async : true,processData: false,// tell jQuery not to process the data
        contentType: false,// tell jQuery not to set contentType
        error : function(request){
            console.log(request.responseText);
        },success : function(json){
            //place your code here
        }
    }); 
});

服务器端(例如:PHP)

//just print $_FILES
print_r($_FILES);

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: &lt;span id=&quot...
jQuery 添加水印 &lt;script src=&quot;../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...