我在db中更新了文件上传的值
我的控制器
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);
}
}
我的模特
public function alfa_update($id, $data)
{
$this->db->where('id', $this->input->post('id'));
$this->db->update('register', $data);
}
附件已保存,但在数据库中我没有文件名。 感谢
答案 0 :(得分:1)
使用此文件获取文件详细信息:$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);
}
请参阅:
https://www.codeigniter.com/user_guide/libraries/file_uploading.html#the-upload-directory
将模型方法alfa_update()
更改为:
public function alfa_update($id, $data)
{
$this->db->where('id',$id);
$this->db->update('register', $data);
}