Implement Simple upload adapter Ckeditor

14 Views Asked by At

I'm trying to implement a CKEditor in my website that allow to upload images but its not working. The server is receiving no files.

This is the editor in the view

 ClassicEditor
    .create( document.querySelector( '#contenido_en' ), {
        simpleUpload: {
                // The URL that the images are uploaded to.
                uploadUrl: '<?=base_url()?>admin/pages/upload/',

                // Headers sent along with the XMLHttpRequest to the upload server.
                headers: {
                    Authorization: 'Bearer <JSON Web Token>'
                }
            },
        link: {
            defaultProtocol: 'https://',
            decorators: {
                openInNewTab: {
                    mode: 'manual',
                    label: 'Abrir en ventana nueva',
                    attributes: {
                        target: '_blank',
                        rel: 'noopener noreferrer'
                    }
                }
            }
        },
        htmlSupport: {
                allow: [
                    {
                        name: /.*/,
                        attributes: true,
                        classes: true,
                        styles: true
                    }
                ]
            },

        licenseKey: '',
        htmlEncodeOutput : true,
        mediaEmbed: {
            previewsInData: true
        },
        
        
    } )

    .then( editor => {

        window.editor = editor;

    } )
    
    
    .catch( error => {
        console.error( 'Oops, something went wrong!' );
        console.error( 'Please, report the following error on https://github.com/ckeditor/ckeditor5/issues with the build id and the error stack trace:' );
        console.warn( 'Build id: c6h88q57dj85-kkgxfgc2wty2' );
        console.error( error );
    } );

And this is the controller function

 use ResponseTrait;
    public function pagesUpload($id = null)
    {   
        helper('form');
        $img = $this->request->getFile('upload');
        log_message('error',$img ?? 'null');
        if ($img->isValid() && ! $img->hasMoved()) {
            $newName = $img->getRandomName();
            if($id)
            {
                $img->move(FCPATH . 'public/images/contenido/'.$id.'/', $newName);
                $pathimagen = base_url('public/images/contenido/'.$id.'/'.$newName);
            }
            else{
                $img->move(FCPATH . 'public/images/contenido/', $newName);
                $pathimagen = base_url('public/images/contenido/'.$newName);
            }
            $data = ['url' => $pathimagen];            
            return $this->respond($data);
            }
    }

When I upload a image on the ckeditor, I got a 500 Internal Server Error, because $img is null after this $img = $this->request->getFile('upload');

0

There are 0 best solutions below