Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

sunrise's avatar

file can not be submitted in form

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?

0 likes
1 reply
neilherbertuk's avatar

Pretty sure you need to add enctype="multipart/form-data" to your form tag

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

Neil

3 likes

Please or to participate in this conversation.