[英]Cannot upload file, CKEditor 5 uploading image using PHP (CodeIgniter 3)
I am trying to upload images via CKEditor 5, the image is uploaded fine but CKEditor shows this error: "cannot upload file" and removes the image from the editor cannot upload file我正在尝试通过 CKEditor 5 上传图像,图像上传正常,但 CKEditor 显示此错误:“无法上传文件”并从编辑器中删除图像无法上传文件
This is my controller:这是我的 controller:
public function uploadCkeditor()
{
$config['upload_path'] = './assets/admin/img/uploads';
$config['allowed_types'] = 'gif|jpg|png|jpg';
$config['max_size'] = 2000;
$new_name = 'blog-'.date("Y-m-d").'-'.time();
$config['file_name'] = $new_name;
$this->load->library('upload', $config);
if(!$this->upload->do_upload('upload')){
echo json_encode(array('error'=> $this->upload->display_errors()));
} else {
$uploadData = $this->upload->data();
echo json_encode(array('file_name'=> $uploadData['file_name']));
}
}
This is CKEditor script:这是 CKEditor 脚本:
<script src="<?= base_url();?>assets/admin/js/ckeditor.js"></script>
<script>
var myEditor;
ClassicEditor.create(document.getElementById('detail'),
{
ckfinder: {
uploadUrl: 'uploadCkeditor'
}}).then( editor => {
console.log( 'Editor was initialized', editor );
myEditor = editor;} ).catch( err => {
console.log( err );} );</script>
I ran into the same issue, and fixed it by returning the following json response at the end of my upload handling function:我遇到了同样的问题,并通过在上传处理 function 结束时返回以下 json 响应来修复它:
return new JsonResponse([
'uploaded' => true,
'fileName' => $image,
'url' => $url
], 200);
It seems like you can also include an error
, with a number
and a message
key, if needed.如果需要,您似乎还可以包含
error
,带有number
和message
键。
Note that I ran into this issue in a Symfony project, rather than a Codeigniter project, but It should work the same way.请注意,我在 Symfony 项目而不是 Codeigniter 项目中遇到了这个问题,但它应该以相同的方式工作。 My answer is based on this answer.
我的答案是基于这个答案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.