M
M
marq2022-04-16 10:12:41
Laravel
marq, 2022-04-16 10:12:41

Ckeditor + laravel how to upload an image?

Good afternoon, I attached the ckeditor editor to laravel, but I got an error when loading images, at the beginning it says "File uploaded successfully" and immediately "Incorrect server response" although the image is stored in the folder
Editor connection:

var editor = CKEDITOR.replace( 'ckeditor',{
        filebrowserUploadUrl: "{{route('ckeditor.image-upload', ['_token' => csrf_token() ])}}",
        filebrowserUploadMethod: 'form'
        } );


Image upload:
class CkeditorController extends Controller
{
    public function upload(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('/images'), $fileName);
            $CKEditorFuncNum = $request->input('CKEditorFuncNum');
            $url = asset('/images/'.$fileName); 
            $msg = 'Image successfully uploaded'; 
            $response = "<script>window.parent.CKEDITOR.tools.callFunction($CKEditorFuncNum, '$url', '$msg')</script>";
               
            @header('Content-type: text/html; charset=utf-8'); 
            echo $response;

        }
    }
}

Has anyone had the same problem and can't find a solution

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question