Я пытаюсь загрузить изображение из текстовой области WYSIWYG (TinyMCE), но это не работает, выдает ошибку «Файл не выбран».
Я использую составную форму, конфликтует ли она с другим «входным файлом»?
Спасибо.
Здесь это код, который я использую.
Просмотр (.twig)
{{ form_open_multipart() }}
...
Texto
{{ form_textarea('text',set_value('text') ? set_value('text') : post.text|raw,'class="form-control editor"') }}
{{ form_close() }}
Контроллер
public function upload_image_tinymce() {
//Check whether user upload picture
if (!empty($_FILES['image']['name'])) {
$config['upload_path'] = ADDONPATH.'themes/escolamagica/img/escolamagica-blog/';
$config['allowed_types'] = 'jpg|jpeg|png|gif';
$config['file_name'] = $_FILES['image']['name'];
$config['overwrite'] = TRUE;
$config['max_size'] = '10240';
$config['max_width'] = '10000';
$config['max_height'] = '10000';
$this->load->library('upload', $config);
$this->upload->initialize($config);
if ($this->upload->do_upload('image')) {
$picture = str_replace('\\', '/', base_url().'img/escolamagica-blog/'.$_FILES['image']['name']);
} else {
echo 'CONFIG';
var_dump($config);
echo 'IMAGE';
var_dump($_FILES);
echo 'ERROR';
$error = array('error' => $this->upload->display_errors());
var_dump($error);
die;
$picture = '';
}
} else {
$picture = '';
}
return $picture;
}
Javascript
function initImageUpload(editor) {
// create input and insert in the DOM
var inp = $('');
$(editor.getElement()).parent().append(inp);
// add the image upload button to the editor toolbar
editor.addButton('imageupload', {
text: '',
icon: 'image',
onclick: function(e) { // when toolbar button is clicked, open file select modal
inp.trigger('click');
}
});
// when a file is selected, upload it to the server
inp.on("change", function(e){
uploadFile($(this), editor);
});
}
function uploadFile(inp, editor) {
var input = inp.get(0);
var data = new FormData();
data.append('image[file]', input.files[0]);
$.ajax({
url: BASE_URL + 'admin/blog/upload_image_tinymce',
type: 'POST',
data: data,
processData: false, // Don't process the files
contentType: false, // Set content type to false as jQuery will tell the server its a query string request
success: function(data, textStatus, jqXHR) {
console.log(data);
editor.insertContent('');
},
error: function(jqXHR, textStatus, errorThrown) {
if(jqXHR.responseText) {
errors = JSON.parse(jqXHR.responseText).errors
alert('Error uploading image: ' + errors.join(", ") + '. Make sure the file is an image and has extension jpg/jpeg/png.');
}
}
});
}
tinymce.init({
language: "pt_PT",
language_url: BASE_URL + "/admin/js/pt_PT.js",
selector: ".editor",
height: 600,
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"
],
toolbar1: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link imageupload",
toolbar2: "print preview media | forecolor backcolor emoticons",
image_advtab: !0,
setup: function(editor) {
initImageUpload(editor);
}
Подробнее здесь: https://stackoverflow.com/questions/450 ... t-selected
Codeigniter - do_upload «Файл не выбран» ⇐ Php
Кемеровские программисты php общаются здесь
1729052942
Anonymous
Я пытаюсь загрузить изображение из текстовой области WYSIWYG (TinyMCE), но это не работает, выдает ошибку «Файл не выбран».
Я использую составную форму, конфликтует ли она с другим «входным файлом»?
Спасибо.
Здесь это код, который я использую.
Просмотр (.twig)
{{ form_open_multipart() }}
...
Texto
{{ form_textarea('text',set_value('text') ? set_value('text') : post.text|raw,'class="form-control editor"') }}
{{ form_close() }}
Контроллер
public function upload_image_tinymce() {
//Check whether user upload picture
if (!empty($_FILES['image']['name'])) {
$config['upload_path'] = ADDONPATH.'themes/escolamagica/img/escolamagica-blog/';
$config['allowed_types'] = 'jpg|jpeg|png|gif';
$config['file_name'] = $_FILES['image']['name'];
$config['overwrite'] = TRUE;
$config['max_size'] = '10240';
$config['max_width'] = '10000';
$config['max_height'] = '10000';
$this->load->library('upload', $config);
$this->upload->initialize($config);
if ($this->upload->do_upload('image')) {
$picture = str_replace('\\', '/', base_url().'img/escolamagica-blog/'.$_FILES['image']['name']);
} else {
echo 'CONFIG';
var_dump($config);
echo 'IMAGE';
var_dump($_FILES);
echo 'ERROR';
$error = array('error' => $this->upload->display_errors());
var_dump($error);
die;
$picture = '';
}
} else {
$picture = '';
}
return $picture;
}
Javascript
function initImageUpload(editor) {
// create input and insert in the DOM
var inp = $('');
$(editor.getElement()).parent().append(inp);
// add the image upload button to the editor toolbar
editor.addButton('imageupload', {
text: '',
icon: 'image',
onclick: function(e) { // when toolbar button is clicked, open file select modal
inp.trigger('click');
}
});
// when a file is selected, upload it to the server
inp.on("change", function(e){
uploadFile($(this), editor);
});
}
function uploadFile(inp, editor) {
var input = inp.get(0);
var data = new FormData();
data.append('image[file]', input.files[0]);
$.ajax({
url: BASE_URL + 'admin/blog/upload_image_tinymce',
type: 'POST',
data: data,
processData: false, // Don't process the files
contentType: false, // Set content type to false as jQuery will tell the server its a query string request
success: function(data, textStatus, jqXHR) {
console.log(data);
editor.insertContent('');
},
error: function(jqXHR, textStatus, errorThrown) {
if(jqXHR.responseText) {
errors = JSON.parse(jqXHR.responseText).errors
alert('Error uploading image: ' + errors.join(", ") + '. Make sure the file is an image and has extension jpg/jpeg/png.');
}
}
});
}
tinymce.init({
language: "pt_PT",
language_url: BASE_URL + "/admin/js/pt_PT.js",
selector: ".editor",
height: 600,
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"
],
toolbar1: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link imageupload",
toolbar2: "print preview media | forecolor backcolor emoticons",
image_advtab: !0,
setup: function(editor) {
initImageUpload(editor);
}
Подробнее здесь: [url]https://stackoverflow.com/questions/45032630/codeiginter-do-upload-file-not-selected[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия