Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

upload image to ckeditor in laravel Incorrect server response

i am trying to upload image through ckeditor 4 enter image description here

when i press send it the server getting this Error Incorrect Server Response

here is my controller

public function mediauploadpost(Request $request){
    $CKEditor = $request->input('CKEditor');
    $funcNum  = $request->input('CKEditorFuncNum');
    $message  = $url = '';
    if (Input::hasFile('upload')) {
        $file = Input::file('upload');
        if ($file->isValid()) {
            $filename =rand(1000,9999).$file->getClientOriginalName();
            $file->move(public_path().'/wysiwyg/', $filename);
            $url = url('wysiwyg/' . $filename);
        } else {
            $message = 'An error occurred while uploading the file.';
        }
    } else {
        $message = 'No file uploaded.';
    }
    return '<script>window.parent.CKEDITOR.tools.callFunction('.$funcNum.', "'.$url.'", "'.$message.'")</script>';
}
like image 920
Sid Heart Avatar asked Aug 17 '18 09:08

Sid Heart


2 Answers

Remove this one

$res = "<script>window.parent.CKEDITOR.tools.callFunction(" .$funcNum.  "," . $url . "," .$message. ")</script>"

Use this code in your return .

return response()->json([ 'fileName' => 'your file name put here', 'uploaded' => false, 'url' => $url, ]);
like image 84
Aslam Patel Avatar answered Sep 22 '22 19:09

Aslam Patel


I had this same issue recently, and the solution was to add this line to my ckeditor-config.js file:

config.filebrowserUploadMethod = 'form';
like image 22
DisgruntledGoat Avatar answered Sep 25 '22 19:09

DisgruntledGoat