image - 如果我将 id 的值更改为数据库,则使用 tinymce 上传图像时出现错误“无法上传图像:HTTP 错误:500”
问题描述
我有一个tinymce代码将插入mysql数据库,ID从使用insert_id()的最后一个id输入到另一个函数,当给id赋值时会出现错误“上传图像失败:HTTP错误: 500”,你们能帮帮我吗?
这是我的控制器:
function save()
{
$judul = $this->input->post('judul');
$isi = $this->input->post('isi');
$kategori = implode(',', $this->input->post('kategori'));
$c_date=date("Y-m-d H:i:s");
$data = array(
'judul' => $judul,
'isi' => $isi,
'kategori' => $kategori,
'publish' => $c_date
);
$ids = $this->text_editor_model->simpan($data);
$this->upload_image($ids);
redirect('text_editor');
}
function upload_image($ids)
{
$config['upload_path'] = './berkas/news/';
$config['allowed_types'] = 'jpg|png|jpeg';
//$config['max_size'] = 0;
$this->load->library('upload', $config);
if ( !$this->upload->do_upload('file')) {
$this->output->set_header('HTTP/1.0 500 Server Error');
exit;
} else {
$file = $this->upload->data();
$this->output
->set_content_type('application/json', 'utf-8')
->set_output(json_encode(['location' => base_url().'/berkas/news/'.$file['file_name']]))
->_display();
$count = count($file['file_name']);
for ($i=0; $i < $count ; $i++) {
$data2[$i]['id_berita'] = $ids; //error in here
$data2[$i]['img_name'] = $file['file_name'];
}
$this->text_editor_model->insert_img($data2);
exit;
}
}
这是我的 tinymce 脚本:
tinymce.init({
selector: "#editor",
height: 400,
plugins: [
"advlist autolink lists link image charmap print preview hr anchor pagebreak",
"searchreplace wordcount visualblocks visualchars code fullscreen",
"insertdatetime nonbreaking save table contextmenu directionality",
"emoticons template paste textcolor colorpicker textpattern"
],
toolbar: "insertfile undo redo | styleselect | fontsizeselect | bold italic | forecolor backcolor | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image responsivefilemanager table",
images_upload_url: "<?php echo site_url('text_editor/upload_image')?>",
automatic_uploads: true,
image_advtab : true,
file_picker_types: 'image',
relative_urls: false,
remove_script_host: false,
image_dimensions: false,
image_class_list: [
{title: 'Responsive', value:'img-responsive'}
],
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.readAsDataURL(file);
reader.onload = function () {
var id = 'blog-' + (new Date()).getTime();
var blobCache = tinymce.activeEditor.editorUpload.blobCache;
var blobInfo = blobCache.create(id, file, reader.result);
blobCache.add(blobInfo);
cb(blobInfo.blobUri(), { title: file.name });
};
};
input.click();
}
});
解决方案
推荐阅读
- angular - Angular - 类型“desc”不能分配给类型“null”
- javascript - 如何使用javascript将html表单数据保存在txt文件中
- docker - 在主机 Nginx 后面使用多个 dockerized Nginx
- node.js - Flutter socket.io 客户端未通过 https 与 node.js socket.io 服务器连接
- jmeter - JMeter Beanshell - 将文件另存为 pdf
- javascript - 我该怎么做才能从 java 解析 javascript 类?
- c - 为什么我在任务管理器中没有找到要杀死的进程时经常得到“ld返回1退出状态”?
- splunk - Splunk 搜索格式
- php - 如何将标签与 ui-select 链接
- python - Python - AWS Cognito 在用户电子邮件更改时需要验证电子邮件确认