Tum Lina Tum Lina - 2 months ago 12
PHP Question

How to request file with array name of input file?

Just wondering why I can't get value of array name from input type file.

HTML:

<input type="file" name="collateral_photo[]" id="collateral_photo" class="default"/>


The name of this input file is an array.

PHP Laravel

return Request::file('collateral_photo');


The return result is [{}]

What I want right now just how to get value from this input file with array name.

Please, please help me out.

Thank you very much for any help.

Answer Source

use the below code, since the name attribute is an array

$files = Request::file('collateral_photo');
return $files[0];

or if you want second file

return $files[1];

//if you want to access second file and so on

you need to access the file with array index specified.

If you want to return the whole files array itself then use

return $files