Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to request file with array name of input file?

Tags:

html

php

laravel

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.

like image 636
Tum Lina Avatar asked Jun 11 '15 02:06

Tum Lina


1 Answers

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
like image 116
Sourabh Kumar Sharma Avatar answered Sep 28 '22 18:09

Sourabh Kumar Sharma