gagal upload image

permisi gan mau tanya ini kenapa upload image di ci gagal terus

my controller:

 public function savedosen() {

        $this->load->library('upload');
        $config['upload_path'] = './images/';
        $config['allowed_types'] = 'gif|jpg|png|jpeg|bmp';
        $config['max_size'] = '2048';
        $config['max_width']  = '1288';
        $config['max_height']  = '768';

    $this->upload->initialize($config);

    if ($this->upload->do_upload('foto'))
    {
        $gambar = $this->upload->data();
        $nik       = $this->input->post('nik');
        $nama      = $this->input->post('nama_dosen');
        $jk  = $this->input->post('jk');
        $agama  = $this->input->post('agama');
        $tempat  = $this->input->post('tempat');
        $tanggal  = $this->input->post('tanggal');
        $alamat  = $this->input->post('alamat');
        $email  = $this->input->post('email');
        $hp  = $this->input->post('hp');
        $title  = $this->input->post('title');
        $status  = $this->input->post('status');
        $prodi  = $this->input->post('prodi');
        $password  = $this->input->post('confirm_password');
         $data = array(
            'nik_dosen'     =>$nik,
            'nama_dosen'    => $nama,
            'jenis_kelamin' => $jk,
            'agama'         => $agama,
            'tempat_lahir'  =>$tempat,
            'tgl_lahir'     => date('Y-m-d', strtotime($tanggal)),
            'alamat'        => $alamat,
            'email'         => $email,
            'hp'            => $hp,
            'status'        => $status,
            'title_dosen'   => $title,
            'foto_dosen'    => $gambar['file_name'],
            'pass_dosen'    => md5($password),
            'id_prodi'      => $prodi,

        );
        $this->dosen_model->insertdosen($data);

        redirect('dosen');

    }
    else
    {
        echo "Gagal";
    }
}

my view upload poto:

<div class="form-group ">
                                          <label for="firstname" class="control-label col-lg-2">Upload Gambar
                                          <span class="required"> * </span></label>
                                          <div class="col-lg-6">
                                              <input class=" form-control" id="foto" name="foto" type="file"  />
                                          </div>
                                      </div>

dimana letak kesalahannya?

avatar ikhwansr
@ikhwansr

68 Kontribusi 3 Poin

Diperbarui 7 tahun yang lalu

3 Jawaban:

error nya apa ? cek di console kalo ga ada .. error nya ga masuk ke database , apa ga bisa save ?

avatar farah92
@farah92

49 Kontribusi 10 Poin

Dipost 7 tahun yang lalu

https://www.sekolahkoding.com/forum/upload-file-oop-php

mungkin bisa jadi referensi . saya buat di CI juga

avatar farah92
@farah92

49 Kontribusi 10 Poin

Dipost 7 tahun yang lalu

errornya langsung ke else gan ("gagal"),dan data tidak tersimpan

avatar ikhwansr
@ikhwansr

68 Kontribusi 3 Poin

Dipost 7 tahun yang lalu

Login untuk ikut Jawaban