首页 > 解决方案 > 如果我将 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();
    }
});

标签: imagecodeigniteruploadtinymcetinymce-5

解决方案


推荐阅读