0

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

1
  • maybe you should replace $this->input->post('id') with $id, I'm not sure if the Model has access to post data. Commented Apr 10, 2017 at 16:42

1 Answer 1

1

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);  
   }  
Sign up to request clarification or add additional context in comments.

1 Comment

$data['image_name '] = $this->upload->data('file_name'); It Works!!!!!! thanks a lot!!!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.