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
This is my 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:
<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>