默认情况下,tinymce图像没有浏览按钮,您可以在其中单击并查看用于选择图像的对话框。在我的代码中我试图将图像选择器按钮添加到tinymce但是发现很难将它与images_upload_handler结合起来。最后,我如何使用成功回调来更新images_upload_base_path。
tinymce.init({
...
images_upload_handler: function (blobInfo, success, failure) {
var xhr, formData;
xhr = new XMLHttpRequest();
xhr.withCredentials = false;
xhr.open('POST', "postAcceptor.php");
xhr.onload = function() {
var json;
if (xhr.status != 200) {
failure("HTTP Error: " + xhr.status);
return;
}
json = JSON.parse(xhr.responseText);
if (!json || typeof json.location != "string") {
failure("Invalid JSON: " + xhr.responseText);
return;
}
success(json.location);
};
formData = new FormData();
formData.append('file', blobInfo.blob(), blobInfo.filename());
xhr.send(formData);
}
});
答案 0 :(得分:1)
我真的不明白为什么,但对我来说images_upload_handler
不能正常运作...... =(
使用file_picker_callback
代替,就像我在这个例子中找到的那样:
https://codepen.io/nirajmchauhan/pen/EjQLpV