I\'m stuck on a problem with updating image. I\'ve created image upload which works fine but I also want it to be updated. When I add a need image it updates correctly but I
public function update()
{
$id=$this->input->post("id");
$s_em=$this->input->post("s_em");
$s_na=$this->input->post("s_na");
if($_FILES[file]['name']!="")
{
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png|jpeg|jpe|pdf|doc|docx|rtf|text|txt';
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload('file'))
{
$error = array('error' => $this->upload- >display_errors());
}
else
{
$upload_data=$this->upload->data();
$image_name=$upload_data['file_name'];
}
}
else{
$image_name=$this->input->post('old');
}
$data=array('s_em'=>$s_em,'s_na'=>$s_na,'file'=>$image_name);
$this->Students_m->db_update($data,$id);
}
in the view file add the following
<input type="hidden" id="old" name="old" value="<?php echo $da['file'] ?>">
try this..let me know this works or not.
Be always careful when you upload image with a same name. It's uploaded successfully but you can't see the if changed on the front end of it has same URL and same name that is because your browser have Cached previous Image.
Make sure image is updated successfully on server first