gpt4 book ai didi

How do I get images to upload to the server with TinyMCE?(如何使用TinyMCE获取要上传到服务器的图像?)

转载 作者:bug小助手 更新时间:2023-10-24 19:01:27 28 4
gpt4 key购买 nike



I am trying to store images added via the TinyMCE editor to the server. It appears as if the file that handles image uploads is never reached. I might be blind, but it seems as though I followed their documentation, so nothing is wrong.

我正在尝试将通过TinyMCE编辑器添加的图像存储到服务器。似乎从未访问过处理图像上传的文件。我可能是盲目的,但似乎我遵循了他们的文档,所以没有任何问题。


Here's the TinyMCE initialization:

以下是TinyMCE的初始化:


//Initialize the TinyMCE text editor
tinymce.init({
selector: '#tinymce-selector',
menubar: 'edit format view insert',
removed_menuitems: 'backcolor lineheight fontfamily fontsize',
plugins: 'lists advlist accordion anchor charmap emoticons image link media quickbars searchreplace code table',
toolbar: 'undo redo | blocks | bold italic underline forecolor | alignleft aligncenter alignright alignjustify | insert | emoticons charmap',
toolbar_groups: {
insert: {
icon: 'browse',
tooltip: 'Insert',
items: 'link | image media | table | bullist numlist'
}
},
image_upload_url: 'assets/functions/news-manager/image-uploader.php',
block_formats: 'Paragraph=p; Header 1=h1; Sub Header 1=h2; Sub Header 2=h3', //Sets the content blocks for the editor
quickbars_insert_toolbar: false, //Disables quick image and quick table toolbar
link_default_target: '_blank', //Sets target of links to _blank by default
media_dimensions: false, //Disables dimensions on media input (set automatically)
relative_urls: false, //Disables relative URL functionality - links will be outputted as they are inputted
mobile: { //Enables the menubar on mobile phones
menubar: true
},
content_style: `
@import url('https://fonts.googleapis.com/css2?family=Open+Sans&display=swap');
body {
font-family: 'Open Sans'
}`, //Defines the font for the text editor
encoding: 'xml', //Encodes quotes and other special characters
min_height: 750, //Defines the minimum height of the editor
style_formats: [ //Defines options show under Format -> Formats
{ title: 'Headings', items: [
{ title: 'Header 1', format: 'h1' },
{ title: 'Sub Header 1', format: 'h2' },
{ title: 'Sub Header 2', format: 'h3' }
]},
{ title: 'Inline', items: [
{ title: 'Bold', format: 'bold' },
{ title: 'Italic', format: 'italic' },
{ title: 'Underline', format: 'underline' },
{ title: 'Strikethrough', format: 'strikethrough' },
{ title: 'Superscript', format: 'superscript' },
{ title: 'Subscript', format: 'subscript' },
{ title: 'Code', format: 'code' }
]},
{ title: 'Align', items: [
{ title: 'Left', format: 'alignleft' },
{ title: 'Center', format: 'aligncenter' },
{ title: 'Right', format: 'alignright' },
{ title: 'Justify', format: 'alignjustify' }
]}
]
});

For image upload URL, I also tried a full address https://example.com/...... which didn't work either.

对于图片上传地址,我也尝试了完整的地址https://example.com/......这也不管用。


This is the AJAX where the form is submitted and the images are to be uploaded.

这是提交表单和上传图像的AJAX。


//Submission handler for the form
var submission_flag = 0;
$('#new-post-form').submit(function(e) {

e.preventDefault();

if (submission_flag === 0) {

submission_flag = 1;

//Upload tinyMCE images to the server
tinymce.activeEditor.uploadImages(function(success) {

console.log('images uploaded');

});

const form = $(this),
url = form.attr('action');

tinyMCE.triggerSave(); //Save TinyMCE Data

$.ajax({
url: url,
type: 'POST',
data: new FormData(this),
contentType: false,
cache: false,
processData: false,
global: false,
success: function(data) {
response = JSON.parse(data);

if (response.flag == 0) {

//Send the user to the new post (if live) OR back to the manager (if draft)
// window.location.replace(response.url);
console.log('post upload complete!');

} else {

//Report errors to the client
openStateNotification('error', response.errors);

//Remove hidden 'is-draft' flag element
$("#js-is-draft").remove();

//Reset flags
draft_flag = 0;
submission_flag = 0;

}

},
.....

I obviously don't understand something, so any help is appreciated. Thanks.

我显然不明白一些事情,所以任何帮助都是非常感谢的。谢谢。


更多回答
优秀答案推荐
更多回答

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com