我认为您应该尝试重新创建每个请求的csrf令牌
试试这个代码示例…
对于js函数
var csrfName = '<?php echo $this->security->get_csrf_token_name(); ?>', csrfHash = '<?php echo $this->security->get_csrf_hash(); ?>';("#avatar").change(function(){ var link = $("#avatar").val(); var dataJson = { [csrfName]: csrfHash, id: "hello", link: link }; $.ajax({ url : "<?php echo base_url('main/test'); ?>", type: 'post', data: dataJson, success : function(data) { csrfName = data.csrfName; csrfHash = data.csrfHash; alert(data.message); } });});
对于控制器
public function test() { $config['upload_path'] = './uploads/'; $config['allowed_types'] = 'gif|jpg|png'; $config['max_size'] = 500; $config['max_width'] = 260; $config['max_height'] = 260; $reponse = array( 'csrfName' => $this->security->get_csrf_token_name(), 'csrfHash' => $this->security->get_csrf_hash() ) $this->load->library('upload', $config); if (!$this->upload->do_upload('link')) { $reponse['message'] = "error"; } else { $data = array('upload_data' => $this->upload->data()); $image_name = $data['upload_data']['file_name']; $reponse['message'] = $image_name; } echo json_enpre($reponse);}
让我知道,祝你好运
注意: 当有人要求您向问题发布更多数据时,请勿将其发布为评论或答案,最好自己编辑问题并添加内容
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)