How can a user upload a profile picture on my codeigniter registration form How can a user upload a profile picture on my codeigniter registration form codeigniter codeigniter

How can a user upload a profile picture on my codeigniter registration form


I modified your code. Try this

public function register() {  $data = array();  $config = array(      'upload_path' => 'upload',      'allowed_types' => 'gif|jpg|png|jpeg',  );  $this->load->library('upload', $config);  if (!$this->upload->do_upload('profiel_foto')) {    $error = array('error' => $this->upload->display_errors());    // var_dump( $error); die; check errors   } else {    $fileName = $this->upload->data();    $data['profiel_foto'] = $fileName['file_name'];  }  // voeg gebruiker toe aan database  $data = array (      'voornaam'=>$_POST['voornaam'],      'achternaam'=>$_POST['achternaam'],      'email'=>$_POST['email'],      'wachtwoord'=>  ($_POST['wachtwoord']),      'startdatum'=>date('Y-m-d'),      'postcode'=>$_POST['postcode'],      'huisnummer'=>$_POST['huisnummer'],      'woonplaats'=>$_POST['woonplaats'],      'beschrijving'=>$_POST['beschrijving'],      'geboortedatum'=>$_POST['geboortedatum'],      'geslacht'=>$_POST['geslacht'],  );  $this->db->insert('users', $data);  $this->session->set_flashdata("success", "Uw account is nu geregistreerd, u kunt nu inloggen");  redirect("auth/register", "refresh");}


replace

$config['upload_path'] = './upload/';         $config['allowed_types'] = 'gif|jpg|png|jpeg';         $this->load->library('upload', $config);         $this->input->post('profiel_foto');         $data_upload_files = $this->upload->data();         $image = $data_upload_files['./upload/'];

With

                    $target_dir = "upload/";                    $target_file = $target_dir . time().basename($_FILES["profiel_foto"]["name"]);                    $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);                    $imgName = time().basename($_FILES["profiel_foto"]["name"]);                    move_uploaded_file($_FILES["profiel_foto"]["tmp_name"], $target_file);

Your insert function

$data = array (                    'voornaam'=>$_POST['voornaam'],                    'achternaam'=>$_POST['achternaam'],                    'email'=>$_POST['email'],                    'wachtwoord'=>  ($_POST['wachtwoord']),                    'startdatum'=>date('Y-m-d'),                    'postcode'=>$_POST['postcode'],                    'huisnummer'=>$_POST['huisnummer'],                    'woonplaats'=>$_POST['woonplaats'],                    'beschrijving'=>$_POST['beschrijving'],                    'geboortedatum'=>$_POST['geboortedatum'],                    'geslacht'=>$_POST['geslacht'],                    'profiel_foto'=>$imgName                    );                $this->db->insert('users',$data);