Demo only. Everything you upload is visible to every other visitor of this demo, and is deleted again within minutes. Actions are logged, including your IP address. Do not upload anything private, unlawful, or that you are not entitled to share.
CKEditor 4 does not call back into your page the way TinyMCE does. It opens a URL of your own in
a popup window and expects that page to hand the result back through
CKEDITOR.tools.callFunction(). The integration is therefore two files: the editor
configuration, and a small page the editor opens.
First point filebrowserBrowseUrl at the picker page. The endpoint is passed along so
the picker does not have to hardcode it:
<script src="https://cdn.ckeditor.com/4.22.1/standard/ckeditor.js"></script>
<script>
document.addEventListener('DOMContentLoaded', () => {
CKEDITOR.replace('ckeditorId', {
filebrowserBrowseUrl: './ckeditor4_win.htm?endpoint='
+ encodeURIComponent(window.location.origin + '/endpoint/index.php'),
filebrowserWindowWidth: '640',
filebrowserWindowHeight: '480'
});
});
</script>
Then the picker page itself. CKEditor opens it in a popup and adds CKEditorFuncNum
to the query string; that number identifies the callback waiting in the opener. Dosiero runs in
mode: 'iframe' here, because the popup window already exists — this is
ckeditor4_win.htm in full:
<iframe style="width: 100%;height:100vh;border:0"></iframe>
<script type="module">
import {Dosiero} from '/dosiero/dosiero.min.mjs';
const urlParams = new URLSearchParams(window.location.search),
CKEditorFuncNum = urlParams.get('CKEditorFuncNum') || '',
endpoint = urlParams.get('endpoint') || '';
new Dosiero({
mode: 'iframe',
iframe: document.querySelector('iframe'),
endpoint: endpoint,
onSelectFile: function (files) {
for (let file of files) {
if (file.type === 'file') {
window.opener.CKEDITOR.tools.callFunction(CKEditorFuncNum, file.url);
break;
}
}
window.close();
},
onClose: function () {
window.close();
},
}).open();
</script>
Take the endpoint from the server, not from the query string. This demo passes it in the URL to keep the two files independent, but that makes it a reflected parameter — a crafted link could point the picker at someone else's server. In a real installation print the endpoint into the page on the server side.
More
about CKEditor's file manager configuration. Note that CKEditor 4 reached end of life in June
2023 and 4.22.1 is the last release usable without a paid support contract.