fefe
fefe

Reputation: 9055

Jasny multiple file upload with other form elements

I try to use Jasny fileupload to pass multiple files to php inside of a form, which on submit event should be uploaded via ajax posted datas. But I can't get it to work. I can not append jasny uploads to posted datas.

If there is a better workaround what would be better to implement instead jasny I would like to know about.

I init my upload fields as follows

jQuery('.fileupload').fileupload({});

I try to catch theme on submit

wizard.on("submit", function(wizard) {
    jQuery.ajax({
      //here When I serialize the form I do not get the files
    });
});

Upvotes: 5

Views: 3766

Answers (3)

Laukik Patel
Laukik Patel

Reputation: 743

Try with

var data = new FormData();
jQuery.each($('#file')[0].files, function(i, file) {
  data.append('file-'+i, file);
});

So now you have a FormData object, ready to be sent along with the XMLHttpRequest.

$.ajax({
   url: 'php/upload.php',
   data: data,
   cache: false,
   contentType: false,
   processData: false,
   type: 'POST',
   success: function(data){
      alert(data);
   }
});

Upvotes: 7

Michał Zalewski
Michał Zalewski

Reputation: 3368

Please look at jQuery File Upload (https://github.com/blueimp/jQuery-File-Upload), it's support multiple files uploading and have backend implemented for PHP.

Upvotes: 2

user3173819
user3173819

Reputation: 62

Let's go
1st you need put the multiple at your input file 2sd
you will need use the canvas and sent one by one at an loop in your script
give one look at https://plugins.jquery.com/tag/canvas/
http://canvasquery.com/

Upvotes: -2

Related Questions