Support the ongoing development of Laravel.io →
Requests Input Forms

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

Last updated 3 years ago.
0

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() }}
0
Solution

Add enctype property to your upload form. It's mandatory for upload.

<form name="le_form" action="/ft" method="POST" enctype="multipart/form-data">
Last updated 8 years ago.
0

Sign in to participate in this thread!

PHPverse

Your banner here too?

JamesA1 jamesa1 Joined 31 Jul 2016

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.