UploadFile callback is not being triggered in CKEditor
Asked Answered
T

1

1

I am using latest Full CKEditor (4.5.3) with Office2013 style enabled.

I added filebrowserImageUploadUrl option here:

CKEDITOR.replace( 'news_content' ,
            {
                "filebrowserImageUploadUrl": "/path/to/script.php"
            });

When an image is uploaded, backed is returning proper HTML and headers to CKEditor, but what it does - just displays that JavaScript code and doesn't actually trigger that. If I copy-paste that JS to the browser (Chrome) console - it works (switches tab to the first one and inputs the image).

Please find screenshot attached. What have I missed?

enter image description here

P.S> The first argument is taken from the Request when file is being uploaded, so in that case it's = 1 (it's not the issue :))

Teakwood answered 23/8, 2015 at 18:19 Comment(3)
Any chance the response is sent with incorrect headers, like plain/text is enforced etc?Gerald
Well, I tried with setting explicitly to "text/html", no result. I have a possible solution. Will check tonight.Teakwood
Well, to be honest, Wiktor, I re-checked again headers and probably isolation has mad it's deal. I was explicitly setting headers to plain/text instead of text/html. That's why opensource and working in collaboration - rocks! Thanks :)Teakwood
T
0

As it was guessed by @Wiktor the issue was in setting proper headers. I was almost there, setting wrong headers.

Right headers are obviously: "text/html" (not "plain/text", it recognizes it just as a text in this case)

    $uploadResponse = new Response();
    $uploadResponse->headers->set('Content-type', 'text/html');

    $content = "<script type=\"text/javascript\">\n";
    $content .= "window.parent.CKEDITOR.tools.callFunction(" . $funcNum . ", '/uploads/news_image/" . $response['uploadedName'] . "', '');\n";
    $content .= "</script>";

    $uploadResponse->setContent($content);
Teakwood answered 24/8, 2015 at 19:50 Comment(4)
am facing the same issue can you help me in thisMaddening
what is $funcNum?Liturgist
@Liturgist It is function number, something that can be scrapped using console. An argument used by CKEditor - see I explained in the original question.Teakwood
@IliaShakitko thanks but what I want is the name of the file in the aspx page so that I can save it into a database. I succeeded in uploading the fileLiturgist

© 2022 - 2024 — McMap. All rights reserved.