Reputation: 1
I have a problem with update in my db the value of file upload
My controller
public function c_piloti_update()
{
// Modifica i valori scheda pilota
$id= $this->input->post('id');
$data = array(
'nominativo' => $this->input->post('nominativo'),
'fotografia' => $this->input->post('fotografia')
);
$config['upload_path'] = './uploads/avatar/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = 1000;
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload('fotografia'))
{
$error = array('error' => $this->upload->display_errors());
$this->load->view('upload_form', $error);
}
else
{
$this->load->model('alfa/alfa_model');
$this->piloti_model->alfa_update($id,$data);
redirect('alfa/alfa-edit/'.$id);
}
}
My Model
public function alfa_update($id, $data)
{
$this->db->where('id', $this->input->post('id'));
$this->db->update('register', $data);
}
The attachment is saved, but in the DB i haven't the file name. thanks
Upvotes: 0
Views: 104
Reputation: 9717
Get File details using this : $this->upload->data();
if ( ! $this->upload->do_upload('fotografia'))
{
$error = array('error' => $this->upload->display_errors());
$this->load->view('upload_form', $error);
}
else
{
$data['image_name '] = $this->upload->data('file_name');
//here image_name is column name in table
$this->load->model('alfa/alfa_model');
$this->piloti_model->alfa_update($id,$data);
redirect('alfa/alfa-edit/'.$id);
}
see this :
https://www.codeigniter.com/user_guide/libraries/file_uploading.html#the-upload-directory
Change model method alfa_update()
to this :
public function alfa_update($id, $data)
{
$this->db->where('id',$id);
$this->db->update('register', $data);
}
Upvotes: 1