如何显示图像在Froala编辑器ajax响应后,在Codeigniter一个很好的链接

How to display images in Froala Editor after ajax respond with a good link in Codeigniter?

本文关键字:Codeigniter 链接 很好 一个 ajax 显示 何显示 图像 Froala 编辑器 响应      更新时间:2023-09-26

我正在使用Codeigniter3Froala Editor在我的网站上发布一些内容我也创建了一个图像上传当点击插入图像在Froala编辑器和Ajax响应后的图像链接,但它不显示在Froala编辑器

问题图片不显示在Froala编辑器,但它已经上传到服务器(localhost)。

这是我的Froala编辑器

<script>
    $(function () {
        $('#edit').editable({
            inlineMode: false,
            mediaManager: false,
            showInsertImage:true,
            imageUploadParam: 'up_img',
            setHTML:true,
            imageUploadURL: 'http://localhost/site/gotoadmin/image/edit_img',
              imageErrorCallback: function (data) { 
              if (data.errorCode == 1) {
                console.log ('bad link')
              }
              else if (data.errorCode == 2) {
                console.log ('bad response')
              }
              else if (data.errorCode == 3) {
                console.log ('upload error')
              }
          }
        })
    });
</script>
这是图像控制器中使用CI3上传图像的功能
public function edit_img() {
    $this->load->helper(array('form', 'url'));
    $config['upload_path'] = '../assets/img/editor';
    $config['image_library'] = 'gd2';
    $config['allowed_types'] = 'gif|jpg|png';
    $config['max_size'] = '1000000';
    $config['max_width'] = '102400';
    $config['max_height'] = '768000';
    $this->load->library('upload', $config);
    $token = $this->security->get_csrf_hash();
    $res = FALSE;
    if (!$this->upload->do_upload('up_img')) {
        $response = FALSE;
    } else {
        $data = $this->upload->data();
        $response = 'http://localhost/site/assets/img/editor/'.$data['file_name'];
    }
    echo stripslashes(json_encode($response));
}

这是我的响应数据

"http://localhost/site/assets/img/editor/back.jpg" (This link is work when I copy past to browser I can see the images)

谢谢

响应应该是JSON格式。您的响应应该以不同的方式创建:

$response = new StdClass;
$response->link = 'http://localhost/site/assets/img/editor/'.$data['file_name'];
echo stripslashes(json_encode($response));

在Froala Editor Php图片上传文章中有更多的细节。