0

In PHP if you give the same name with square brackets to several inputs, it's going to create an array with the values of all inputs, like that:

<input name="userfile[]" type="file" />

<input name="userfile[]" type="file" />

My question is could I do that but with the multiple attribute, like:

<input name="userfile[]" type="file" multiple />

<input name="userfile[]" type="file" multiple />

This is going to create an array with the elements of each input?

Kmdd
  • 1
  • 3
  • See [this from the manual](https://www.php.net/manual/en/features.file-upload.multiple.php) and [this from SO](https://stackoverflow.com/a/12006515/231316) – Chris Haas Mar 18 '22 at 16:56
  • Assuming you want multiple inputs that accept multiple files; you might need `name="userfile[][]"` because the input will be an array of files and then you'll need an array of inputs. If you want multiple files but don't need multiple inputs, then just `` – AbraCadaver Mar 18 '22 at 17:12
  • I am sorry, I have to ask, WHY would you need the _then could I do_ You could but what possible purpose would it serve? Once you add `multiple` or `multiple="multiple"` you are allowing the user to select any number of files for upload – RiggsFolly Mar 18 '22 at 17:28
  • There may be a purpose in `` and `` but that is not what you asked – RiggsFolly Mar 18 '22 at 17:30
  • @RiggsFolly yes, the user is allowed to send multiple files at once, but they must be all in the same folder, if the user attempts to send a "second round" of files that were located in another folder, the first uploaded files would be lost, being replaced by the new ones. And also, yes I'm naming the inputs with different names, but this is going create two arrays called "firstSet[]" and other called "secondSet[]" and I wish I could have only one – Kmdd Mar 18 '22 at 17:38
  • Well as you have no control over where the user put their files, this is something you cannot control. Probably a message saying, "put all your eggs in one basket before uploading" would be all you can do here – RiggsFolly Mar 18 '22 at 17:43
  • @AbraCadaver, that was the approach I've come in, it works fine. Ty. – Kmdd May 13 '22 at 13:01

0 Answers0