1

i was just trying to upload my file to laravel

This is my upload view

<form action="/DoUpload" method="post">
    {{ csrf_field() }}
    <input type="file" name="Image" value="Image">
    <input type="submit" name="" value="Upload!">
</form>

this is my upload controller

public function index(Request $request){
    $IMAGE = $request->file('Image');
    dd($IMAGE);
    }

when i try to dd the image, the page said that it is null..

1
  • add file="true" in your form. It will solve your issue Commented Nov 6, 2017 at 13:28

2 Answers 2

2

Define multipart/form-data enctype for your form, Like:

<form action="/DoUpload" method="post" enctype="multipart/form-data">
    {{ csrf_field() }}
    <input type="file" name="Image" value="Image">
    <input type="submit" name="" value="Upload!">
</form>

this will be able to send files through POST.

Sign up to request clarification or add additional context in comments.

Comments

0

If you are using laravel then try to follow its LaravelCollective/html package.

In LaravelCollective this can be solve by just a simple line

{{Form::open(array('url' => 'your_url', 'method' => 'post', 'files' => true))}}

{!! Form::close() !!}

which will create

<form action="your_url" method="post" files="true">

in laravel files=true do same the enctype="multipart/form-data" do.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.