javascript - Ckeditor upload image return 403 forbidden error on codeigniter -


i'm using ckeditor codeigniter;

ckeditor.editorconfig = function( config ) {     config.width = '68%';    config.toolbargroups= [  {name:"styles","groups":["styles"]}, {name: 'basicstyles', groups: [ 'basicstyles', 'cleanup' ] }, {name: "links"}, {name: "paragraph", groups: [ 'list', 'indent', 'blocks', 'align'] }, '/', {name: 'colors' }, {name: 'clipboard', groups: [ 'clipboard', 'undo' ] }, {name:"insert","groups":["insert"]},   ];    config.extraplugins = 'mathjax,codesnippet,autogrow,colordialog,tableresize';    config.codesnippet_theme = 'zenburn';    config.autogrow_maxheight = 600;    config.filebrowseruploadurl = '../ckeditor/do_upload'; }; 

this config.js file of ckeditor

class ckeditor extends ci_controller{    public function __construct(){  parent::__construct(); $this->load->helper('url'); $this->load->helper('form'); }    public function do_upload(){  $config['upload_path'] = './resources/uploads/';  $config['allowed_types'] = 'gif|jpg|jpeg|png';  $this->load->library('upload'); $this->upload->initialize($config);  $funcnum = $this->input->get('ckeditorfuncnum');  if ( ! $this->upload->do_upload('upload')){     $error = array('error' => $this->upload->display_errors());     $message = 'fail';     $url = ''; } else {    $data = array('upload_data' => $this->upload->data());    $message = 'success';    $url = base_url().'resources/uploads/'. $this->upload->data()['file_name']; }  echo "<script type='text/javascript'>window.parent.ckeditor.tools.callfunction($funcnum, '$url', '$message');</script>";  }    public function index(){  echo 'this page used file upload'; $this->load->view('form', array('error' => ''));    }  } 

the do_upload works fine when i'm using ,but ckeditor each time i'm try upload image .i 403 post

http://localhost/ci/index.php/admin/ckeditor/do_upload?ckeditor=editor1&ckeditorfuncnum=1&langcode=zh-cn 403 (forbidden) 

how solve problem, it's annoy me day..is because of lack of hidden fields?

<input type="hidden" name="csrf_test_name" value="3be92cbaaba15d7d08dd7affad23abfd" style="display:none;" /> 

but how can make ckeditor work.cause apprently can't control form ckeditor generated upload image?

_____________________________update_____________________________________________

when set

$config['csrf_protection'] = false; 

in codeigniter's config.php. don't have problem upload image.but want set true.

/* |-------------------------------------------------------------------------- | cross site request forgery |-------------------------------------------------------------------------- | enables csrf cookie token set. when set true, token | checked on submitted form. if accepting user data, | recommended csrf protection enabled. | | 'csrf_token_name' = token name | 'csrf_cookie_name' = cookie name | 'csrf_expire' = number in seconds token should expire. | 'csrf_regenerate' = regenerate token on every submission | 'csrf_exclude_uris' = array of uris ignore csrf checks */ $config['csrf_protection'] = true; $config['csrf_token_name'] = 'csrf_test_name'; $config['csrf_cookie_name'] = 'csrf_cookie_name'; $config['csrf_expire'] = 7200; $config['csrf_regenerate'] = true; $config['csrf_exclude_uris'] = array(); 

so problem may temporary disable csrf_protection on codeigniter. why should temporary disable that? there other way solve problem instead of disable csrf_protection on single url below.

$config['csrf_exclude_uris'] = array(   'admin/ckeditor/do_upload',   '' ); 


Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

php - Find a regex to take part of Email -