Multiple upload, file berhasil terupload ke folder namun data tidak berhasil masuk ke database

Halo rekan-rekan programmer sekolahkoding, mohon izin bertanya terkait dengan permasalahan saya.

Saya telah membuat script multiple upload data, file tersebut berhasil terupload ke dalam folder path namun data (nama file) tsb tidak berhasil masuk ke dalam database.

Kira-kira bagaimana solusinya yaa ??

Untuk memudahkan teman-teman saya sudah melampirkan script codingan di bawah ini.

1. Script Controller

 public function upload()
  {
    $config['upload_path'] = './uploads/file_siswa/';
    $config['allowed_types'] = 'pdf';
    $config['max_size'] = 1050;
    $config['encrypted_name'] = false;
    $this->load->library('upload', $config);

    //akte
    if(!empty($_FILES['akte']['name'])){
      $this->upload->do_upload('akte');
      $data1 = $this->upload->data();
      $akte = $data1['file_name'];
    }

    //kk
    if(!empty($_FILES['kk']['name'])){
      $this->upload->do_upload('kk');
      $data2 = $this->upload->data();
      $kk = $data2['file_name'];
    }

    //ijazah
    if(!empty($_FILES['ijazah']['name'])){
      $this->upload->do_upload('ijazah');
      $data3 = $this->upload->data();
      $ijazah = $data3['file_name'];
    }

    //kip
    if(!empty($_FILES['kip']['name'])){
      $this->upload->do_upload('kip');
      $data4 = $this->upload->data();
      $kip = $data4['file_name'];
    }

    //kks
    if(!empty($_FILES['kks']['name'])){
      $this->upload->do_upload('kks');
      $data5 = $this->upload->data();
      $kks = $data5['file_name'];
    }

    //pkh
    if(!empty($_FILES['pkh']['name'])){
      $this->upload->do_upload('pkh');
      $data6 = $this->upload->data();
      $pkh = $data6['file_name'];
    }

    if($this->form_validation->run()){
      $id = $this->input->post('id');

      $where = array(
        'id_siswa' => $id
      );
      $data = array(
        'akte_file' => $akte, 'kk_file' => $kk, 'ijazah_file' => $ijazah, 'kip_file' => $kip, 'kks_file' => $kks, 'pkh_file' => $pkh
      );
      $this->m_dokumen->update_data($where, $data, 'tb_siswa');
      redirect(base_url(). 'dokumen_siswa/cek_berkas');
    }else{
      $id = $this->input->post('id');
      $where = array(
        'id_siswa' => $id
      );

      $data['siswa'] = $this->m_dokumen->edit_data($where, 'tb_siswa')->result();
      $this->load->view('backend/header_siswa');
      $this->load->view('backend/dokumen_siswa/index', $data);
      $this->load->view('backend/footer_siswa');
    }
    redirect(base_url(). 'dokumen_siswa/cek_berkas');
  }

2. Script View (tampilan form upload)

<div class="xs-pd-20-10">
  <div class="min-height-200px">
    <div class="page-header">
      <div class="row">
        <div class="col-md-6 col-sm-12">
          <div class="title">
            <h4>Dokumen Pribadi</h4>
          </div>
          <nav aria-label="breadcrumb" role="navigation">
            <ol class="breadcrumb">
              <li class="breadcrumb-item">
                <a href="<?php echo base_url(). 'dashboard_siswa' ?>">Dashboard</a>
              </li>
              <li class="breadcrumb-item active" aria-current="page">Dokumen Pribadi</li>
            </ol>
          </nav>
        </div>
      </div>
    </div>
    <?php foreach($siswa as $dok){ ?>
    <form action="<?php echo base_url(). 'dokumen_siswa/upload' ?>" enctype="multipart/form-data" method="POST">
    <div class="row clearfix">
      <div class="col-md-4 col-sm-12 mb-30">
        <div class="pd-20 card-box height-100-p">
          <h5 class="h4">Upload Akte Kelahiran</h5>
          <p><input type="text" class="form-control" name="id" value="<?php echo $dok->id_siswa; ?>" readonly></p>
          <p><input type="file" class="form-control" name="akte" accept=".pdf"></p>
          <small>File pdf maksimal 1MB</small>

        </div>
      </div>
      <div class="col-md-4 col-sm-12 mb-30">
        <div class="pd-20 card-box height-100-p">
          <h5 class="h4">Upload Kartu Keluarga</h5>
          <p><input type="file" class="form-control" name="kk" accept=".pdf"></p>
          <small>File pdf maksimal 1MB</small>

        </div>
      </div>
      <div class="col-md-4 col-sm-12 mb-30">
        <div class="pd-20 card-box height-100-p">
          <h5 class="h4">Upload Ijazah Terakhir</h5>
          <p><input type="file" class="form-control" name="ijazah" accept=".pdf"></p>
          <small>File pdf maksimal 1MB</small>

        </div>
      </div>
      <div class="col-md-4 col-sm-12 mb-30">
        <div class="pd-20 card-box height-100-p">
          <h5 class="h4">Upload KIP</h5>
          <p><input type="file" class="form-control" name="kip" accept=".pdf"></p>
          <small>File pdf maksimal 1MB</small>

        </div>
      </div>
      <div class="col-md-4 col-sm-12 mb-30">
        <div class="pd-20 card-box height-100-p">
          <h5 class="h4">Upload KKS</h5>
          <p><input type="file" class="form-control" name="kks" accept=".pdf"></p>
          <small>File pdf maksimal 1MB</small>

        </div>
      </div>
      <div class="col-md-4 col-sm-12 mb-30">
        <div class="pd-20 card-box height-100-p">
          <h5 class="h4">Upload PKH</h5>
          <p><input type="file" class="form-control" name="pkh" accept=".pdf"></p>
          <small>File pdf maksimal 1MB</small>

        </div>
      </div>
      <div class="col-md-12 col-sm-12 mb-30">
        <div class="pd-20 card-box height-100-p row">
          <h5 class="h4 col-sm-2"><input type="submit" class="btn btn-primary" value="Simpan Berkas"></h5>
          <h5 class="h4 col-sm-2"><a href="<?php echo base_url(). 'dokumen_siswa/cek_berkas' ?>" class=" btn btn-info">Lihat Berkas</a></h5>
        </div>
      </div>
    </div>
    </form>
    <?php } ?>
  </div>
</div>

3. Screenshoot tampilan database

image.png

Noted : Tambahan di sini saya menggunakan syntax update data di CI, jadi saya membuat form upload yg terpisah dengan form insert data awal di tabel ini.

avatar muhammadrifkipermana_google
@muhammadrifkipermana_google

3 Kontribusi 1 Poin

Diperbarui 1 tahun yang lalu

1 Jawaban:

<div>Coba pelan-pelan lakukan "debug" pada aplikasinya<br>bisa dirunut dari atas data apa yang tidak sesuai sebelum masuk ke database<br>seperti melakukan die atau var_dump<br><br><a href="https://sekolahkoding.com/kelas/error-dan-debugging-php">https://sekolahkoding.com/kelas/error-dan-debugging-php</a><br><a href="https://sekolahkoding.com/kelas/belajar-php-dari-dasar/video/die-dan-var-dump">https://sekolahkoding.com/kelas/belajar-php-dari-dasar/video/die-dan-var-dump</a></div>

avatar hilmanski
@hilmanski

2686 Kontribusi 2135 Poin

Dipost 1 tahun yang lalu

Login untuk ikut Jawaban