我正在使用ckeditor,我试图上传文件。 这是我的代码:使用CKeditor上传文件
@extends('app')
@section('header')
<script type="text/javascript" src="{{url('ckeditor/ckeditor.js')}}"></script>
@endsection
@section('content')
<div class="container">
@include('common.errors')
<div class="row">
<div class="col-lg-12">
<div class="row">
<div class="col-lg-9">
{!! Form::model($info, ['route' => ['infos.update', $info->id], 'method' => 'patch','files' => true]) !!}
@include('infos.fields')
{!! Form::close() !!}
</div>
</div>
</div>
</div>
</div>
@endsection
@section('footer')
<script type="text/javascript">
CKEDITOR.replace('editor1',{
filebrowserImageUploadUrl : "{{route('infos.upload')}}",
filebrowserWindowWidth : 800,
filebrowserWindowHeight : 500
});
window.opener.CKEDITOR.tools.callFunction(CKEditorFuncNum,url);
</script>
@endsection
每当我试着上传文件,我得到令牌不匹配错误。表单生成器会自动在主窗体中添加一个隐藏的csrf字段,但由于ckeditor发出的文件上传(POST请求)是通过ajax发生的,所以它给了我这个错误。我知道我可以禁用这个错误,但是当我使用Google时发现禁用它是一种不好的做法。如何停止获取此错误并上传文件?
您应该添加一些文字来备份和解释,而不是它只是作为一个代码块你的答案。 – Minzkraut
你能解释一下你的代码在做什么来解决这个问题吗? – Mike