我面临的问题是,如果我将上传器设置为true,它将直接发送到保存图像的文件中。由于这种行为,图像将不能很好地加载。没有图像,只有一个边框的大小,这是不工作的。
但是,当我将布尔值false附加到它上时,它将作为完整的图像加载到编辑页面中,但当我想将帖子发送到数据库时,它将响应为“无法隐藏blob: Number to BLOB”,并且图像不会转到文件夹中。
经过一些测试,我仍然偶然发现了这个问题。我试过使用if语句:
if(array_key_exists('image',$_POST)){
};但这不起作用,因为在ajax方法中,它看不到它。那我该怎么办?使用false并构建一种将图像插入文件夹或使用true的方法,但在发生事情时延迟过程或将图像发送到目录。
另外,当我使用url图像时,它不会被发送到目录,这对我来说是很好的,但是当我用新的规范调整它时,它将被发送到文件夹中,在编辑器WYSIWYG中是不可见的。
$(document).ready(function() {
tinymce.init ({
theme: 'modern',
selector: '.add_body_structure',
height: 1000,
menubar: true,
branding: false,
toolbar: 'undo redo code | styleselect bold italic forecolor backcolor fontselect fontsizeselect | link paste | alignleft aligncenter alignright alignjustify | outdent indent bullist numlist | removeformat | insert',
plugins: 'code contextmenu print preview searchreplace autolink directionality visualblocks visualchars fullscreen image link media mediaembed template table charmap hr pagebreak nonbreaking anchor toc insertdatetime advlist lists textcolor wordcount imagetools contextmenu colorpicker textpattern help autoresize noneditable',
contextmenu: 'paste | link image inserttable | cell row column deletetable',
advlist_bullet_styles: 'square',
advlist_number_styles: 'lower-alpha,lower-roman,upper-alpha,upper-roman',
statusbar: false,
browser_spellcheck: true,
image_title: true,
automatic_uploads: true, // or false
media_live_embeds: true,
contextmenu: true,
relative_urls: false,
remove_script_host: false,
paste_data_images: true,
encoding: 'xml',
invalid_elements: 'script, input, textarea, textfield, col, colgroup, caption, dir, meta, object, select, option, source, title',
fontsize_formats: '8pt 10pt 12pt 14pt 16pt 18pt 20pt 22pt 24pt 26pt 28pt 30pt 32pt 34pt 36pt 38pt 40pt',
images_upload_url: '/wysiwyg/tinymce_main/wysiwyg_one_page_version2.1/views/home/code_for_images/image_uploader.php',
media_live_embeds: true,
file_picker_callback: function(cb, value, meta) {
var input = document.createElement('input');
input.setAttribute('type', 'file');
input.setAttribute('accept', 'image/*, audio/*, video/*');
input.onchange = function() {
var file = this.files[0];
var reader = new FileReader();
reader.onload = function () {
var id = 'blobid' + (new Date()).getTime();
var blobCache = tinymce.activeEditor.editorUpload.blobCache;
var base64 = reader.result.split(',')[1];
var blobInfo = blobCache.create(id, file, base64);
blobCache.add(blobInfo);
// call the callback and populate the Title field with the file name
cb(blobInfo.blobUri(), { title: file.name });
};
reader.readAsDataURL(file);
};
input.click();
},
images_upload_handler: function (blobInfo, success, failure) {
var xhr, formData;
xhr = new XMLHttpRequest();
xhr.withCredentials = false;
xhr.open('POST', 'image_uploader.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);
}
});
}); images_upload_handler似乎没有为我做任何事。在我的情况下,我是犯了一个错误,还是它什么也不做。
我还使用了Postacceptor.php:https://www.tinymce.com/docs/advanced/php-upload-handler/。很明显它对我起作用了。我把它重命名为image_uploader.php.
编辑:,我还没有找到解决方案,但我知道上面的代码不是问题,至少不是原因。我也可以进一步探讨这个问题,但这将是一个不相关的话题,因此没有找到答案,也可以关闭,因为我不认为这会导致任何结果。
发布于 2017-11-21 06:56:29
由于这种行为,图像将不能很好地加载。没有图像,只有一个边框的大小,这是不工作的。
这是什么意思?看起来,这种行为可能是由集成本身引起的,而不是TinyMCE造成的。
https://stackoverflow.com/questions/47390280
复制相似问题