-1

So this may be easy but I can't figure it out. I have a file field and the name is set dynamically with a variable. I need this name to be an array using $Var[] so that the user can select multiple files. When I try the following I keep getting errors:

"<input id='$Var' name='$Var[]' type='file' multiple/>"
"<input id='$Var' name='$Var".[]."' type='file' multiple/>"
"<input id='$Var' name='".$Var."[]' type='file' multiple/>"

I have tried all three of the above and keep getting errors. When I remove the variable and just type in the field name it works fine.

"<input id='File' name='File[]' type='file' multiple/>"

Not sure if need to escape something or what. Please help and thank you.

user982853
  • 2,362
  • 12
  • 49
  • 76
  • possible duplicate of [How can I select and upload multiple files with HTML and PHP, using HTTP POST?](http://stackoverflow.com/questions/1175347/how-can-i-select-and-upload-multiple-files-with-html-and-php-using-http-post) – Avinash R Apr 05 '15 at 18:27
  • @AvinashR in what world are these two questions duplicates? – Madara's Ghost Apr 07 '15 at 08:26

2 Answers2

0

Use curly braces around your variable name:

"<input id='$Var' name='{$Var}[]' type='file' multiple/>"
n-dru
  • 9,039
  • 2
  • 25
  • 39
0

Use your variable this way;

    <?php
    $fieldName = "FileInput";
    echo "<input id='{$fieldName}' name='{$fieldName}[]' type='file' multiple/>";

And reading this answer may be helpful; https://stackoverflow.com/a/2596838/3399234

Community
  • 1
  • 1
Ugur
  • 1,479
  • 13
  • 19