$ _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.

  • and you show what print_r prints with several files) - Alexey Shimansky

2 answers 2

$_FILES['file']['name'][0] - displays the first letter

$_FILES[0]['name'] - displays the name of the first file

  • All intrigue spoiled (( - Alexey Shimansky

Transfer files correctly:

 <form id = "filesForm" enctype="multipart/form-data" method="post"> <input type="file" multiply name="files[]" /> </form> <script> ... $.ajax({ type: 'POST', data: new FormData(document.getElementById('filesForm')), url: 'ajax/uploaded-image.php', processData: false, contentType: false, success: function (data) { alert(data); } }); </script> 

Pay attention to the data field and the parameters of the field to select a file. On the server you should see in the print_r ($ _ FILES) all uploaded files.