Codeigniter - do_upload «Файл не выбран»Php

Кемеровские программисты php общаются здесь
Ответить
Anonymous
 Codeigniter - do_upload «Файл не выбран»

Сообщение 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);
}


Подробнее здесь: https://stackoverflow.com/questions/450 ... t-selected
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Php»