当我按发送服务器时
收到此错误Incorrect Server Response
这是我的控制器
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>';
}
答案 0 :(得分:3)
我最近也遇到了同样的问题,解决方法是将此行添加到我的ckeditor-config.js
文件中:
config.filebrowserUploadMethod = 'form';
答案 1 :(得分:0)
$res = "<script>window.parent.CKEDITOR.tools.callFunction(" .$funcNum. "," . $url . "," .$message. ")</script>"
return response()->json(['data' => $res]);
答案 2 :(得分:0)
如果您将Java用作后端服务器:返回字符串响应:
"{\n " +
" \"uploaded\": 1,\n" +
" \"fileName\": \"foo.jpg\",\n" +
" \"url\": \"/files/foo.jpg\"\n" +
"}"
有关更多信息,请参见此link。
另外请记住在其余的API上加上注解:produces = MediaType.TEXT_HTML_VALUE
。
答案 3 :(得分:0)
删除此
$res = "<script>window.parent.CKEDITOR.tools.callFunction(" .$funcNum. "," . $url . "," .$message. ")</script>"
在您的退货中使用此代码。
return response()->json([ 'fileName' => 'your file name put here', 'uploaded' => false, 'url' => $url, ]);
答案 4 :(得分:0)
在文件中设置这些属性
<script>
CKEDITOR.replace('textarea_id',{
filebrowserUploadUrl:"upload.php",
filebrowserUploadMethod: "form"
});
</script>
答案 5 :(得分:0)
在laravel 7中
CKEDITOR.replace('body', {
filebrowserUploadUrl:'/admin/general-topic/images', // Route
filebrowserImageUploadUrl:'/admin/general-topic/images', // File location
filebrowserUploadMethod: "form"
})