zwl1619
zwl1619

Reputation: 4232

Laravel :file can not be submitted

I am using laravel 5.5.
My form can not submit file,as follow:

html:

<form action="/profile" method="POST">
    {{ csrf_field() }}
    <input type="text" name="username">   
    <input type="file" name="photo">                           
    <button type="submit">submit</button>                           
</form>                               

controller:

public function store(Request $request)
{
    $file = $request->file('photo');  
    dd($file); //result is  null

    $file = $request->photo;  
     //dd($file);//result is "myphoto.jpg",the name of the file.

    if ($request->hasFile('photo')) {
      dd('ok');  //not be executed.
    }

}

input username is ok,file can not be submitted,why is it?
Is it relative to nginx or php config?

Upvotes: 0

Views: 571

Answers (1)

aaron0207
aaron0207

Reputation: 2333

You have to include enctype='multipart/form-data' in your form

<form action="/profile" method="POST" enctype='multipart/form-data'>

Upvotes: 3

Related Questions