Lars-Janssen's avatar

Fileupload null

Hey,

When I try to upload a file like this:

<div class="form-group">
     <label for="File upload" class="col-lg-2 control-label" >File upload</label>
             <div class="col-lg-10">
                     <input action="" type="file" id="fileinput" enctype="multipart/form data"/>  
               </div>
</div>

When I this in my controller:


    public function storeTicket(makeTicketRequest $request)
    {
        dd($request->get("file"));
     }

It's telling me null. In Jeffreys video he's telling me to add:

enctype="multipart/form data"

But that's not working?

0 likes
3 replies
thecrypticace's avatar
Level 12
  1. Your code lacks a form.
  2. It's enctype="multipart/form-data" (notice the hyphen)
  3. Your input has no name attribute.
  4. I don't think ID attributes can have spaces.
  5. By default laravel uses CSRF validation (so you need a _token field)

Try this:

<form action="… action here …" enctype="multipart/form-data" method="POST">
{{ csrf_field() }}
<div class="form-group">
    <label for="File upload" class="col-lg-2 control-label" >File upload</label>
    <div class="col-lg-10">
        <input type="file" id="fileInput" name="file" />  
    </div>
</div>
</form>
DarkRoast's avatar

The enctype="multipart/form-data" attribute should be added to your <form> element. You are also missing a name attribute for your file input.

<form action="/path/to/upload/route" method="POST" enctype="multipart/form-data">
  <input id="file" name="file" type="file">
</form>

I think you should be using $request->file('file') to get the file too.

Please or to participate in this conversation.