SameenaG's avatar

Laravel 5.2 file upload returning null

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.

0 likes
1 reply
tomopongrac's avatar
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

Please or to participate in this conversation.