0
我使用ajax和codeigniter來提交包含圖像數據的表單。問題是控制器顯示一些錯誤,如「不允許的關鍵字符」。我已經改變了配置文件。但仍然不起作用。請幫我解決這個問題。不允許的關鍵字符。在codeigniter中
Ajax調用:
$("form#wall_add").submit(function() {
var m_data = new FormData();
m_data.append('id', $('input[name=id]').val());
m_data.append('desc', $('input[name=desc]').val());
m_data.append('notify', $('input[name=notify]').val());
m_data.append('dcrp', $('textarea[name=dcrp]').val());
m_data.append('img', $('input[name=post]')[0].files[0]);
$.ajax({
url: '<?php echo base_url();?>controller/method/',
data: m_data,
mimeType: "multipart/form-data",
contentType: false,
processData: false,
type: 'POST',
success: function(result)
{
$('#posts').html(result);
}
});
});
位指示:
public function method(){
$data['added_content'] = $this->model->ins();
$this->load->view('ajax_get_added',$data);
}
型號:
date_default_timezone_set('Asia/Calcutta');
$date = date("Y-m-d H:i:s", time());
$fid = $this->input->post('id');
$desc = $this->input->post('dcrp');
$dtl = $this->input->post('desc1');
$notify = $this->input->post('notify');
$this->load->helper('date');
$config['upload_path'] = './img/post_images/family/';
$config['allowed_types'] = 'gif|jpg|png|jpeg|';
$this->load->library('upload', $config);
$this->upload->initialize($config);
$field_name ="img_post";
$rgpic="0";
if (!$this->upload->do_upload($field_name))
{
$error = $this->upload->display_errors();
$data['error']=$error;
}
else
{
$data = $this->upload->data();
$regpicname=$data['file_name'];
$rgpic="1";
}
if($rgpic!=0)
{
$data = array('date'=>$date,
'status'=>'A',
'img'=>'img/post_images/family/'.$regpicname,
'desc'=>$desc.$dtl,
'id'=>$fid,
'notify'=>$notify
);
}
else{
$data = array(
'date'=>$date,
'status'=>'A',
'desc'=>$desc.$dtl,
'id'=>$fid,
'notify'=>$notify
);
}
看這個http://stackoverflow.com/questions/4197976/codeigniter-disallowed-key-characters –
已經嘗試過這一點。但它不起作用。 – user5060801
關於這個http://stackoverflow.com/questions/10899384/uploading-both-data-and-files-in-one-form-using-ajax –