When I upload an image in Codeigniter its name is saved to the database but not in the default folder. I'am using Ajax to submit the image
My "view" profile
<div id="timelineBackground">
<?php
{
$image_properties = array('src' => base_url("uploads/" . $timeline_image),'width' => '1000px','height'=> '400px','id'=>'coverimg', 'title' => 'That was quite a night','rel' => 'lightbox');
//echo img($image_properties);
?>
<div id="timelineselector">
<?php echo form_open_multipart('',["id"=>"form_cover"]); ?>
<input type="hidden" name="email" value="<?php echo $email ;?>" >
<?php echo form_upload(["name"=>"timelineimage"]); ?>
<?php echo form_submit(["name"=>"submit","value"=>"Submit"]); ?>
<?php echo form_close(); ?>
</div><?php
}
?></div>
here is my ajax code
jQuery('#form_cover').submit(function(e){
e.preventDefault();
var formData = new FormData(this);
var url= '<?php echo base_url("user/coverimage"); ?>';
formData.value
jQuery.ajax({
type: "POST",
url:url,
data: formData,
cache: false,
contentType: false,
processData: false,
success: function(data)
{
$('#coverimg').attr('src',data);
},
error: function(data){
//error function
}
});
});
my controller "user"
public function coverimage(){
$config = [
'upload_path' => './uploads/',
'allowed_types' => 'jpg|gif|png|jpeg',
'max_size' => 10000000000000,
'max_width' => 1024000000,
'max_height' => 7680000000,
];
$this->load->library('upload', $config);
if(!$this->upload->do_upload('timelineimage') ) {
$post = $this->input->post();
unset($post['submit']);
$upload_data = $this->upload->data();
$file_name=$_FILES['timelineimage'];
$this->load->model('Pmodel');
$this->Pmodel->timeline_upload_model($post,$file_name);
$image_properties = array(
'src' => base_url("./uploads/" . $file_name['name']),
'width' => '200px',
'height'=> '200px',
'title' => 'That was quite a night',
'rel' => 'lightbox'
);
// echo img($image_properties);
echo base_url("uploads/" . $file_name['name']);
exit();
}else {
$upload_error = $this->upload->display_errors();
$this->load->view('admin/add_article',compact('upload_error'));
}
}
my model "Pmodel"
public function timeline_upload_model($arr,$arra)
{
$email=$arr['email'];
$image=$arra['name'];
$data=array('timelineimage'=>$image);
$query=$this->db->where('email',$email)->update('user_data',$data);
return $query;
}
Why does it only show the name but not the image?