Reputation: 137
I send file with form like this
<input type="file" class="form-control" name="images[]" multiple enctype="multipart/form-data"/>
but in controller on $request->all()
I get only file name
"images" => array:1 [▼
0 => "just-before-hit.png"
]
How to get file object to store it?
Upvotes: 3
Views: 19673
Reputation: 8979
You can get the file object using $request->file('NAME')
or using $request->FILEINAME
. for more information visit the official laravel docs here and here is the example for you.
$files = $request->file('images');
foreach($files as $file){
// here is your file object
dd($file->getClientOriginalName());
}
You'll need to add enctype="multipart/form-data"
to your form. Otherwise, file upload won't work properly.
Upvotes: 5
Reputation: 389
If that can help
add in your controller : use Illuminate\Http\UploadedFile;
Upvotes: 0
Reputation: 137
So the answer is to add enctype="multipart/form-data"
not only to input but also to <form enctype="multipart/form-data"></form>
tag.
Upvotes: 0
Reputation: 128
You can get file name and of of its property with this $request->file('Name of your input field')
. For more information please check laravel documentation.Documentation
$file = $request->file('Name of your input field');
$filename = $file->getClientOriginalName();
$extension = $file->getClientOriginalExtension();
Upvotes: 0