我正在使用 ckeditor 在 laravel 中上传图像 它工作正常并将图像上传到文件夹,但在前面它给出了“无法上传图像:图像名称”的警报错误,并从编辑器中删除了图像
图像上传控制器:
public function storeImage(Request $request)
{
if ($request->hasFile('upload')) {
$originName = $request->file('upload')->getClientOriginalName();
$fileName = pathinfo($originName, PATHINFO_FILENAME);
$extension = $request->file('upload')->getClientOriginalExtension();
$fileName = $fileName . '_' . time() . '.' . $extension;
$request->file('upload')->move(public_path('media'), $fileName);
$url = asset('media/' . $fileName);
return response()->json(['fileName' => $fileName, 'uploaded'=> true, 'url' => $url]);
}
}
脚本:
<script>
ClassicEditor
.create( document.querySelector( '#longdescription' ), {
ckfinder: {
uploadUrl: "{{route('image.upload').'?_token='.csrf_token()}}",
}
})
.then( editor => {
console.log( editor );
} )
.catch( error => {
console.error( error );
} );
</script>