Why input type="file" multiple downloads only 1 file?

HTML:

<form action="/product/add" method="post" enctype="multipart/form-data">
 <input type="file" id="upload_file" name="upload_file[]" multiple>
</form>

PHP:
if($request->hasFile('upload_file')){
 foreach ($request->file('upload_file') as $value) {
dd($value->getClientOriginalName());
// it generates only 1 file (the name) which was last loaded 
// echo tried
}
exit();
 }

Where wrong?

P. S. I noticed that for multiple selection, hold Shift or Ctrl, it would be no to this, not every thought immediately to this.
July 2nd 19 at 13:15
3 answers
July 2nd 19 at 13:17
Solution
<form action="/product/add" method="post" enctype="multipart/form-data">
 <input type="file" id="upload_file" name="upload_file[]" onchange="preview_image();" multiple>
</form>
I have exactly what is written, the name of the array - jaycee commented on July 2nd 19 at 13:20
Or rather, I have written:

<form action="/product/add" method="post" enctype="multipart/form-data">
 {{ csrf_field() }}
 <input type="file" name="upload_file[]" multiple>
 <button type="submit" class="btn btn-primary form-control">Add Product</button>
</form>
- jaycee commented on July 2nd 19 at 13:23
Request {#41 ▼
#json: null
#convertedFiles: array:1 [▼
"upload_file" => array:1 [▶]
]
why it returns only 1 file. - jaycee commented on July 2nd 19 at 13:26
: 1) Initially you have to form was not an array
2) You must choose 1 file, so the server side comes 1 file. - nicklaus.Will commented on July 2nd 19 at 13:29
: probably need to make Ajax download and display non-selected files, I those the user has uploaded. And then to work with them. Or create each time a new input. Or a bunch of variants. As I understand it, in this case, you must use ctrl or shift to multi-boot. - jaycee commented on July 2nd 19 at 13:32
: Yes, right - nicklaus.Will commented on July 2nd 19 at 13:35
July 2nd 19 at 13:19
because it is not an array
Corrected to name="upload_file[]", it's still displays the name of the last file. - jaycee commented on July 2nd 19 at 13:22
: dd you're doing, kill the script after the first iteration...... - jaycee commented on July 2nd 19 at 13:25
: Done echo $value->getClientOriginalName(); all the same, displays only the last photo. - jaycee commented on July 2nd 19 at 13:28
:
Request {#41 ▼
#json: null
#convertedFiles: array:1 [▼
"upload_file" => array:1 [▼
0 => UploadedFile {#240 ▶}
]
]
why it returns only 1 file. - nicklaus.Will commented on July 2nd 19 at 13:31
dd($request->file('upload_file'))

before the loop - jaycee commented on July 2nd 19 at 13:34
I've added a description of the problem in question. If you hold down shift or Ctrl everything works. I would like without it and then have to figure out how to delete a specific file from multiple input ... . - nicklaus.Will commented on July 2nd 19 at 13:37
: without the shift or ctrl the default code www.w3schools.com/tags/tryit.asp?filename=tryhtml5...

to remove in any way except JS
To use some plugin for full selection and download of files on the front - jaycee commented on July 2nd 19 at 13:40
: eeem, but even the link you gave, there should be the Ctrl or Shift key to press. - bailee_Stant commented on July 2nd 19 at 13:43
July 2nd 19 at 13:21
dd($request->file('upload_file'));
How many number?
You just select a few ?
The question is written:
P. S. I noticed that for multiple selection, hold Shift or Ctrl, it would be no to this, not every thought immediately to this. - jaycee commented on July 2nd 19 at 13:24
: Maybe the Shift and Ctrl keys depend on the browser, Look at the frontend e salvo file you select. In the choose input files after selecting the file should display its quantity. - jaycee commented on July 2nd 19 at 13:27
: Yes, right. - jaycee commented on July 2nd 19 at 13:30
: review the settings of your server, maybe there is a limit. I personally should max_file_uploads = 20 - nicklaus.Will commented on July 2nd 19 at 13:33

Find more questions by tags HTML