简体   繁体   中英

Laravel form update file is null

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..

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 .

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM