I am using Jquery Ajax to upload an image in Codeigniter, But the problem is the image does not get uploaded an I get alert Disallowed key Characters.Below is the model and view I am using.
View:
$("#upload_course_img").on('submit',function(e){
e.preventDefault();
$.ajax({
url: "<?php echo base_url();?>upload_course_image/upload_img",
type: 'POST',
cache: false,
data: new FormData(this),
processData:false,
success: function(data){
alert("data:"+data);
},
error: function(){
alert('Error while request..');
}
});
});
<form method="post" id="upload_course_img" enctype="multipart/form-data">
<input type="file" name="course_img"/>
<input type="submit" name="submit" value="Save" id="submit-id-submit"/>
</form>
Model:
public function upload_img()
{
if($this->input->post('course_img')) {
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$config['max_size'] = '10000';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$this->load->library('upload', $config);
if (!$this->upload->do_upload())
{
}
else
{
}
}
}