最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

how can I upload multiple files at a single browse using jquery or JavaScript - Stack Overflow

programmeradmin5浏览0评论

I am developing a web application in which I have create a page for multiple file upload on a single browse not one file at a time.

User will be able to select multiple file on click on browse.

If some one have solution for this please wele

Thanks!

I am developing a web application in which I have create a page for multiple file upload on a single browse not one file at a time.

User will be able to select multiple file on click on browse.

If some one have solution for this please wele

Thanks!

Share Improve this question edited Nov 21, 2011 at 5:09 Tokendra Kumar Sahu asked Nov 15, 2011 at 13:45 Tokendra Kumar SahuTokendra Kumar Sahu 3,53411 gold badges29 silver badges30 bronze badges 1
  • blueimp.github.io/jQuery-File-Upload – Yasen Commented Jan 30, 2014 at 9:28
Add a ment  | 

2 Answers 2

Reset to default 9

For alternative solution, you can using HTML5 multiple-upload,

HTML

set attribute multiple for your input-file, check this link https://developer.mozilla/en-US/docs/Web/API/Input.multiple

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

JS

to upload file using juery, you can use form-data : https://developer.mozilla/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
        }
    }); 
});  

SERVER-SIDE(ex:PHP)

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

Uploadify is a very good JQuery Plugin for file upload.

It's very easy to use too. From the docs:

$(document).ready(function() {
  $('#file_upload').uploadify({
    'uploader'  : '/uploadify/uploadify.swf',
    'script'    : '/uploadify/uploadify.php',
    'cancelImg' : '/uploadify/cancel.png',
    'folder'    : '/uploads',
    'auto'      : true
  });
});

Then all you need in html is:

<input id="file_upload" name="file_upload" type="file" />

Obviously including the Uploadify scripts too.

发布评论

评论列表(0)

  1. 暂无评论