This question has already been answered:
I can not figure out how to upload 2 or more images to the server.
<script> $("#btnAddAd").click(function () { var files = $('#input-ficons-1').fileinput('getFileStack'); var description = $('#description').val(); var formData = new FormData(); formData.append('description', description); for (var i = 0; i < files.length; i++) { formData.append('file', files); } $.ajax({ type: 'POST', data: formData, url: 'ajax/uploaded-image.php', processData: false, contentType: false, multiple: true, success: function (data) { alert(data); } }); }) </script> PHP: echo '<pre>'; print_r($_FILES['file']); echo '</pre>'; echo '<pre>'; print_r($_FILES['file']); echo '</pre>';
Displays:
<pre>Array ( [name] => CauSYrOVs7k.jpg [type] => image/jpeg [tmp_name] => Z:\tmp\php6923.tmp [error] => 0 [size] => 146070 ) </pre> I can not understand how to go through the array of images in PHP, with JS Ajax, it seems like it transfers all the files.