I try to rename the upload images (3 images) and then insert to mysql. The problem is, $this->db->insert_id();
has to put after the insert query and the $config['file_name']
has to put before uploaded. How should I rename to auto-id then upload and insert?
$config['upload_path'] = 'images/location';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = 2048; //2048KB = 2MB
$config['max_width'] = 2000;
$config['max_height'] = 1500;
$this->load->library('upload', $config);
$this->upload->do_upload('userfile');
$data_upl['image1'] = $this->upload->data('file_name');
$this->upload->do_upload('userfile2');
$data_upl['image2'] = $this->upload->data('file_name');
$this->upload->do_upload('userfile3');
$data_upl['image3'] = $this->upload->data('file_name');
$data = array(
'location_pic' => $data_upl['image1'],
'location_pic2' => $data_upl['image2'],
'location_pic3' => $data_upl['image3']
);
$this->db->insert('oav_event', $data);
$get_id = $this->db->insert_id();
$config['file_name'] = "id".$get_id;
$this->load->view('admin/success', $data_upl);