$ _FILES ['file'] ['name'] [0] returns the first letter of the file name. On the Internet I read a bunch of manuals.
Suppose that the files /home/test/some.html and /home/test/file.bin have been downloaded. In this case, the $ _FILES ['userfile'] ['name'] [0] variable will be set to some.html, and the $ _FILES ['userfile'] ['name'] [1] variable will be set to file.bin. Similarly, the $ _FILES ['userfile'] ['size'] [0] variable will contain some.html file size and so on.
I use denwer, I transfer images through ajax:
for (var i = 0; i < files.length; i++) { formData.append('file', files[i]); } One file is perfectly loaded and saved, but I can not organize sending 2 or more files.
How to get a list of downloaded files in PHP, what would be saved in a loop?
UPD: echo '<pre>'; print_r($_FILES['userfile']); echo '</pre>'; echo '<pre>'; print_r($_FILES['userfile']); echo '</pre>';
displays: <pre></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> Most likely a mistake here:
<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[i]); } $.ajax({ type: 'POST', data: formData, url: 'ajax/uploaded-image.php', processData: false, contentType: false, success: function (data) { alert(data); } }); }) </script> "var files" contains "[object file], [object file]", i.e. 2 images are transmitted.
print_rprints with several files) - Alexey Shimansky