Forms Laravel 5.4文件上载

Forms Laravel 5.4文件上载,forms,laravel,laravel-5,Forms,Laravel,Laravel 5,我使用Laravel5.4,想上传图片。 但是在controllert$request->hasFile('pic')中返回false。 这是我的blade.php: . . . <form action="{{ route('my-url') }}" method="post"> <input type="file" name="pic"> </form> . . . 。 . . . . . 这是我的控制器: <?php namespac

我使用Laravel5.4,想上传图片。 但是在controllert$request->hasFile('pic')中返回false。 这是我的blade.php:

.
.
.
<form action="{{ route('my-url') }}" method="post">
    <input type="file" name="pic">
</form>
.
.
.
。
.
.
.
.
.
这是我的控制器:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class myclass extends Controller {

    public function myfunc(Request $request) {
        if($request->hasFile('pic')){
            // never get this
        }
    }
}
只需在表单中添加
//enctype=“multipart/form data”添加此项,这将
只需在表单中添加
//enctype=“multipart/form data”添加此项,这将
您应该尝试以下方法:

将表单数据编码为“多部分/表单数据”
,这是将文件作为表单数据包含时所必需的

<form action="{{ route('my-url') }}" method="post" enctype="multipart/form-data">
    <input type="file" name="pic">
</form>

您应该尝试以下方法:

将表单数据编码为“多部分/表单数据”,这是将文件作为表单数据包含时所必需的

<form action="{{ route('my-url') }}" method="post" enctype="multipart/form-data">
    <input type="file" name="pic">
</form>


使用需要包含加密类型的文件时,将其添加到表单中:
enctype=“多部分/表单数据”
使用需要包含加密类型的文件时,将其添加到表单中:
enctype=“多部分/表单数据”