MTilsted
MTilsted

Reputation: 5543

Get filebrowserUploadUrl to update url

I am using the plugin image2, and would like the ability to upload images to our server.

I have added config.filebrowserUploadUrl="/CkeditorImageUpload"

to my config.js, and the "Image properties" dialog does have a upload image tab which can upload images to my server. So far so good but the problem is that when an image is uploaded, the url field is not updated in the image properties dialog so the user can't use the uploaded image.

Should my /CkeditorImageUpload return something special to cause the dialog to update?

Upvotes: 1

Views: 658

Answers (1)

Wiktor Walc
Wiktor Walc

Reputation: 5560

Yes, CKEditor expects the upload script to return a <script> tag that calls an anonymous function.

Everything is described in the documentation http://docs.ckeditor.com/#!/guide/dev_file_browser_api - see Example 3 with a PHP example of script that sends a response after a file upload:

<?php
// Required: anonymous function reference number as explained above.
$funcNum = $_GET['CKEditorFuncNum'] ;
// Optional: instance name (might be used to load a specific configuration file or anything else).
$CKEditor = $_GET['CKEditor'] ;
// Optional: might be used to provide localized messages.
$langCode = $_GET['langCode'] ;

// Check the $_FILES array and save the file. Assign the correct path to a variable ($url).
$url = '/path/to/uploaded/file.ext';
// Usually you will only assign something here if the file could not be uploaded.
$message = ;

echo "<script type='text/javascript'>window.parent.CKEDITOR.tools.callFunction($funcNum, '$url', '$message');</script>";
?>

Upvotes: 0

Related Questions