javascript - How to display images in Froala Editor after ajax respond with a good link in Codeigniter? -
i'm using codeigniter3 , froala editor posting content in website , i'm create image upload when click on insert images in froala editor , after respond ajax link of images don't show in froala editor
issue images don't show in froala editor has upload server(localhost).
here froala editor
<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>
and function in images controller using ci3 upload images
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)); }
here respond data
"http://localhost/site/assets/img/editor/back.jpg" (this link work when copy past browser can see images)
thanks
the response should json. response should created differently:
$response = new stdclass; $response->link = 'http://localhost/site/assets/img/editor/'.$data['file_name']; echo stripslashes(json_encode($response));
there more details on froala editor php image upload article.
Comments
Post a Comment