我正在尝试使用表单和Laravel上传文件。我的表格:
<form action="testUpload" nctype='multipart/form-data' method='POST'>
<input type="hidden" name="_Token" value="{{ csrf_token() }}">
<div class="col-md-12" style="margin-top: 25px">
<div class="input-group mb-3">
<div class="custom-file">
<input type="file" class="custom-file-input" id="inputGroupFile01">
<label class="custom-file-label" id="uploadFile" for="inputGroupFile01">Choose file</label>
</div>
</div>
<input type="submit" class="btn btn-success" />
</div>
</form>
我的路线如下:
Route::group(['middleware' => 'web'], function(){
Route::post('/testUpload', 'uploadController@upload');
});
而我的控制器:
public function upload(){
$data = Request::all();
return $data;
}
当前,按下按钮时出现419页过期错误。我想念什么?我已经尝试清除所有路线缓存
You are missing CSRF field in your form. All forms should have it. You can add it easy with
@csrf
between<form>
and</form>
Note:
nctype='multipart/form-data'
should beenctype='multipart/form-data'