Level 51
In form element you need to add enctype="multipart/form-data"
<form name="le_form" action="/ft" method="POST" enctype="multipart/form-data">
1 like
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, thanks.
In form element you need to add enctype="multipart/form-data"
<form name="le_form" action="/ft" method="POST" enctype="multipart/form-data">
Please or to participate in this conversation.