admin 管理员组文章数量: 1086019
I need to add all features to TinyMCE Editor and I want to allow upload files, audio/video, and images.
Images uploading work ok, but have a problem with other files. I have pickers everywhere but files not sent to php.
I can't understand how to proceed with audio/video files. Basically how to send FILE to my PHP handler and get url to saved file (I use PHP handler from TinyMCE documentatin).
tinyMCE.init({
selector: '.tinyMCE-content-full',
height: 400,
theme: 'modern',
plugins: [
'advlist autolink lists link image charmap print preview hr anchor pagebreak',
'searchreplace wordcount visualblocks visualchars code fullscreen',
'insertdatetime media nonbreaking save table contextmenu directionality',
'emoticons template paste textcolor colorpicker textpattern imagetools codesample toc help image code'
],
toolbar1: 'undo redo | insert | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image | fontsizeselect',
toolbar2: 'print preview media | forecolor backcolor emoticons | codesample help',
fontsize_formats: '8pt 10pt 12pt 14pt 18pt 24pt 36pt',
image_advtab: true,
file_picker_types: 'file image media',
images_upload_handler: function (blobInfo, success, failure) {
var xhr, formData;
xhr = new XMLHttpRequest();
xhr.withCredentials = false;
xhr.open('POST', '/clients/tinymceFileUpload');
var token = $('[name="csrf-token"]').prop('content');
xhr.setRequestHeader("X-CSRF-Token", token);
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);
},
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.readAsDataURL(file);
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 });
};
};
input.click();
}
});
I need to add all features to TinyMCE Editor and I want to allow upload files, audio/video, and images.
Images uploading work ok, but have a problem with other files. I have pickers everywhere but files not sent to php.
I can't understand how to proceed with audio/video files. Basically how to send FILE to my PHP handler and get url to saved file (I use PHP handler from TinyMCE documentatin).
tinyMCE.init({
selector: '.tinyMCE-content-full',
height: 400,
theme: 'modern',
plugins: [
'advlist autolink lists link image charmap print preview hr anchor pagebreak',
'searchreplace wordcount visualblocks visualchars code fullscreen',
'insertdatetime media nonbreaking save table contextmenu directionality',
'emoticons template paste textcolor colorpicker textpattern imagetools codesample toc help image code'
],
toolbar1: 'undo redo | insert | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image | fontsizeselect',
toolbar2: 'print preview media | forecolor backcolor emoticons | codesample help',
fontsize_formats: '8pt 10pt 12pt 14pt 18pt 24pt 36pt',
image_advtab: true,
file_picker_types: 'file image media',
images_upload_handler: function (blobInfo, success, failure) {
var xhr, formData;
xhr = new XMLHttpRequest();
xhr.withCredentials = false;
xhr.open('POST', '/clients/tinymceFileUpload');
var token = $('[name="csrf-token"]').prop('content');
xhr.setRequestHeader("X-CSRF-Token", token);
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);
},
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.readAsDataURL(file);
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 });
};
};
input.click();
}
});
Share
Improve this question
asked Sep 11, 2017 at 12:25
dkruchokdkruchok
1,9193 gold badges21 silver badges25 bronze badges
2
- Did you solve your problem? – Lukas Hieronimus Adler Commented Mar 4, 2020 at 14:14
- As I noted in an answer below I used responsivefilemanager. – dkruchok Commented Mar 5, 2020 at 8:51
3 Answers
Reset to default 3I resolveed this by using responsivefilemanager
This thing made much easier to insert images and other files to content area.
You can only add HTML5 video and audio elements to the editable area. It also adds the item Insert/edit video under the Insert menu as well as a toolbar button. The option you need is called media_live_embeds
When you enable this option users will see a live preview of embedded video content within the editable area, rather than a placeholder image. This means that users can play a video clip, such as YouTube, within the editor.
This option is enabled by default and accepts URLs input into the source field or embed field in the dialog box by the user.
tinymce.init({
selector: "textarea", // change this value according to your HTML
plugins: "media",
menubar: "insert",
toolbar: "media",
media_live_embeds: true
});
file_picker_types: 'image',
file_picker_callback: function(cb, value, meta) {
var input = document.createElement('input');
input.setAttribute('type', 'file');
input.setAttribute('accept', 'image/*');
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();
},
本文标签: javascriptTinyMCE upload audiovideoimagesfilesStack Overflow
版权声明:本文标题:javascript - TinyMCE upload audiovideoimagesfiles - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/p/1744030336a2521379.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论