I was trying to upload a file in Laravel 5.2, but when I try to access it using the file method it always returns null. Here is my html:
<html>
<body>
<form name="le_form" action="/ft" method="POST">
{{csrf_field()}}
<input type="file" name="le_file"/>
<input type="submit">
</form>
</body>
</html>
In my routes:
Route::get('ft',function(){
return view('ft');
});
Route::post('ft','HomeController@ft');
and in my HomeController, the ft method:
public function ft(Request $request) {
return $request->file('le_file'); //Returns null.
}
Any help is appreciated, thank
I think you need to indicate that the form involves files.
{{ Form::open( array('url' => '/ft', 'class'=>'form-horizontal', 'files' => true)) }}
<input type="file" name="le_file"/>
<input type="submit">
{{ Form::close() }}
Add enctype property to your upload form. It's mandatory for upload.
<form name="le_form" action="/ft" method="POST" enctype="multipart/form-data">
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community