hello there is an AJAX request

 function askquestion() { if (inask) return false; var data = new FormData(); data.append('image', $('.uploadimg:eq(0) input').prop('files')[0]); data.append('image', $('.uploadimg:eq(1) input').prop('files')[0]); $.ajax({ url: 'здесь мой сайт', type: 'post', cache: false, contentType: false, processData: false, data: data, success: function(data) { // } }); } 

Here is the php code:

print_r($_FILES);

and as seen in the image, the ajax request successfully transmitted 2 images, but php sees only 1, what is the problem with?

enter image description here

  • 2
    Try this: data.append('image[]' - Vitaly
  • thanks, it helped) - turik97
  • 2
    burned the second acc)) - Alexey Shimansky
  • so damn here the reputation slipped, I can not ask questions)) - turik97

1 answer 1

You add parameters to ajax , and thus the first parameter is overwritten. Here is your code:

 data.append('image', $('.uploadimg:eq(0) input').prop('files')[0]); data.append('image', $('.uploadimg:eq(1) input').prop('files')[0]); 

And it is necessary so:

 data.append('image1', $('.uploadimg:eq(0) input').prop('files')[0]); data.append('image2', $('.uploadimg:eq(1) input').prop('files')[0]);