如何使用jQuery添加多个文件上传到现有的功能

时间:2015-05-08 18:16:59

标签: jquery ajax

我有下载上传功能,一次上传一张图片,如何调整它以处理多个文件?

function _(el){
    return document.getElementById(el);
}
function uploadFile(){
    var checked_box = $('input:checkbox:checked').val();
    var file = _("image").files[0];
    var imageFile =$("#image").val();
    var formdata = new FormData();
    formdata.append( 'action','add_photo');
    formdata.append("image", file);
    jQuery.each($("input[name^='image']")[0].files, function(i, file) {
    formdata.append('photo['+i+']', file);
    }); 
    var ajax = new XMLHttpRequest();
    ajax.upload.addEventListener("progress", progressHandler, false);
    ajax.addEventListener("load", completeHandler, false);
    ajax.addEventListener("error", errorHandler, false);
    ajax.addEventListener("abort", abortHandler, false);
    ajax.open("POST", "includes/add_photo.inc.php?checked_box="+checked_box);
    ajax.send(formdata);
}

相关文件输入html

<input name="image[]" id="image" type="file" multiple style="display:none" value=""/>

0 个答案:

没有答案