How can you integrate a custom file browser/uploader with CKEditor?

前端 未结 8 1549
南方客
南方客 2020-11-28 00:14

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

8条回答
  •  余生分开走
    2020-11-28 00:56

    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.

    
    

    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(,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 = '';
    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.

提交回复
热议问题