如何将自定义文件浏览器/上传器与CKEditor集成? [英] How can you integrate a custom file browser/uploader with CKEditor?

查看:238
本文介绍了如何将自定义文件浏览器/上传器与CKEditor集成?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

官方文档不够清楚 - 将自定义文件浏览器/上传器与CKEditor集成的正确方法是什么? (v3 - 不是FCKEditor)

解决方案

在实例化CKEditor时注册您的自定义浏览器/上传程序。您可以为图片浏览器和一般文件浏览器指定不同的网址。

 < script type =text / javascript > 
CKEDITOR.replace('content',{
filebrowserBrowseUrl:'/ browser / browse / type / all',
filebrowserUploadUrl:'/ browser / upload / type / all',
filebrowserImageBrowseUrl:'/ browser / browse / type / image',
filebrowserImageUploadUrl:'/ browser / upload / type / image',
filebrowserWindowWidth:800,
filebrowserWindowHeight:500
});
< / script>

您的自定义代码将收到一个名为CKEditorFuncNum的GET参数。保存它 - 这是你的回调函数。让我们说你把它放入 $ callback



当有人选择一个文件时,运行这个JavaScript来通知CKEditor文件:

  window.opener.CKEDITOR.tools.callFunction(<?php echo $ callback;?& url)

其中url是他们选择的文件的URL。可选的第三个参数可以是您希望在标准警报对话框中显示的文本,例如非法文件或其他内容。



CKEditor的上传选项卡将在上传字段中提交一个文件 - 在PHP中,转到$ _FILES ['upload']。 CKEditor希望您的服务器输出的是一个完整的JavaScript块:

  $ output ='< html>< body> ; script type =text / javascript> window.parent.CKEDITOR.tools.callFunction('。$ callback。','。$ url。','。$ msg。'); script>< / body>< / html>'; 
echo $ output;

同样,你需要给它回调参数,文件的URL, 。如果消息是空字符串,则不显示任何内容;如果消息是错误,则url应为空字符串。



官方的CKEditor文档并不完整,但如果你按照上面的说法,它会像一个冠军。


The official documentation is less than clear - what's the correct way to integrate a custom file browser/uploader with CKEditor? (v3 - not FCKEditor)

解决方案

Start by registering your custom browser/uploader when you instantiate CKEditor. You can designate different URLs for an image browser vs. a general file browser.

<script type="text/javascript">
CKEDITOR.replace('content', {
    filebrowserBrowseUrl : '/browser/browse/type/all',
    filebrowserUploadUrl : '/browser/upload/type/all',
    filebrowserImageBrowseUrl : '/browser/browse/type/image',
filebrowserImageUploadUrl : '/browser/upload/type/image',
    filebrowserWindowWidth  : 800,
    filebrowserWindowHeight : 500
});
</script>

Your custom code will receive a GET parameter called CKEditorFuncNum. Save it - that's your callback function. Let's say you put it into $callback.

When someone selects a file, run this JavaScript to inform CKEditor which file was selected:

window.opener.CKEDITOR.tools.callFunction(<?php echo $callback; ?>,url)

Where "url" is the URL of the file they picked. An optional third parameter can be text that you want displayed in a standard alert dialog, such as "illegal file" or something. Set url to an empty string if the third parameter is an error message.

CKEditor's "upload" tab will submit a file in the field "upload" - in PHP, that goes to $_FILES['upload']. What CKEditor wants your server to output is a complete JavaScript block:

$output = '<html><body><script type="text/javascript">window.parent.CKEDITOR.tools.callFunction('.$callback.', "'.$url.'","'.$msg.'");</script></body></html>';
echo $output;

Again, you need to give it that callback parameter, the URL of the file, and optionally a message. If the message is an empty string, nothing will display; if the message is an error, then url should be an empty string.

The official CKEditor documentation is incomplete on all this, but if you follow the above it'll work like a champ.

这篇关于如何将自定义文件浏览器/上传器与CKEditor集成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆