Reputation: 743
i am trying to upload image through ckeditor 4
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>';
}
Upvotes: 10
Views: 11150
Reputation: 39
in laravel 7
CKEDITOR.replace('body', {
filebrowserUploadUrl:'/admin/general-topic/images', // Route
filebrowserImageUploadUrl:'/admin/general-topic/images', // File location
filebrowserUploadMethod: "form"
})
Upvotes: 0
Reputation: 45
set the these propertis in your file
<script>
CKEDITOR.replace('textarea_id',{
filebrowserUploadUrl:"upload.php",
filebrowserUploadMethod: "form"
});
</script>
Upvotes: 1
Reputation: 894
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, ]);
Upvotes: 2
Reputation: 72510
I had this same issue recently, and the solution was to add this line to my ckeditor-config.js
file:
config.filebrowserUploadMethod = 'form';
Upvotes: 17
Reputation: 185
If you are using java as your backend server: return string response:
"{\n " +
" \"uploaded\": 1,\n" +
" \"fileName\": \"foo.jpg\",\n" +
" \"url\": \"/files/foo.jpg\"\n" +
"}"
See this link fro more information.
Also remember to to have annotation: produces = MediaType.TEXT_HTML_VALUE
over your rest API.
Upvotes: 3
Reputation: 126
$res = "<script>window.parent.CKEDITOR.tools.callFunction(" .$funcNum. "," . $url . "," .$message. ")</script>"
return response()->json(['data' => $res]);
Upvotes: 0