duplicat data saat upload file

saat upload file data duplicat 2 jadi file yang keupload di filezilla ketika saya cek ada 3 gambar sedangkan di database masuk 1 file gambar

ini controller nya
public function tambah_galeri_pk()
  {
    // $id = decrypt_url($id);
    $id = $this->input->post('id_perkutut');

    if (!empty($_FILES['gambar']['name'])) {
      if ($_FILES['gambar']['size']<307200) {
      $config['upload_path']    = './perkutut/galeri_perkutut/';
      $config['allowed_types']  = 'gif|jpg|png|jpeg';
      $config['overwrite']			= true;
      $config['file_name']      = round(microtime(true)*1000);

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

      if (!$this->upload->do_upload('gambar')) {
        $this->session->set_flashdata('notif', $this->upload->display_errors('',''));
        redirect('Perkutut/galeri_perkutut');
      }else{
        $data1 = $this->upload->data();
        $foto_lama = $data1['file_name'];
        $config['image_library']='gd2';
        $config['source_image']='./perkutut/galeri_perkutut/'.$data1['file_name'];
        $config['create_thumb']='TRUE';
        $config['width']='400';
        $config['height']='400';
        $config['new_image']='./perkutut/galeri_perkutut/'.$data1['file_name'];

        $this->load->library('image_lib',$config);
        $this->image_lib->resize();

        $data['id_perkutut'] = $id;
        $data['gambar'] = $data1['raw_name'].'_thumb'.$data1['file_ext'];

        // echo $data['gambar'];
        // die;

        $cek = $this->db->insert('galeri_perkutut',$data);

        $paths =  'perkutut/galeri_perkutut/';
        if ($foto_lama != "default_perkutut.png"){
          unlink($paths.$foto_lama);
        }

        if ($cek) {
          $notif = [
            'status' => 'success',
            'message' => 'Selamat , Tambah Galeri Berhasil !'
          ];
        }else{
          $notif = [
            'status' => 'error',
            'message' => 'Tambah Galeri Gagal, Silahkan Coba Lagi !'
          ];
        }
        $this->session->set_flashdata('notif', $notif);
        redirect('Perkutut/galeri_perkutut/'.encrypt_url($id));
      }
    }else{
      $notif = [
        'status' => 'error',
        'message' => 'Gambar Perkutut Terlalu Besar ! Gambar harus berukuran 300kb'
      ];
      $this->session->set_flashdata('notif', $notif);
      redirect('Perkutut/perkutut');
    }
    }else{
      $notif = [
        'status' => 'error',
        'message' => 'Tambah Galeri Gagal, Silahkan Coba Lagi !'
      ];
      $this->session->set_flashdata('notif', $notif);
      redirect('Perkutut/galeri_perkutut/'.encrypt_url($id));
    }
  }
ini viewnya 
<form method="POST" action="<?php echo base_url('Perkutut/tambah_galeri_pk');?>" enctype="multipart/form-data" role="form">
              <div class="modal-body">
                  <div class="row">

                    <div class="file-upload">
                      <button class="file-upload-btn" type="button" onclick="$('.file-upload-input').trigger( 'click' )">Tambah Gambar</button>
                      <br><small style="color:red">*Ukuran Maks.300Kb</small>


                      <div class="progress mt-2" style="width:100%;background:transparent;">
                          <div class="progress-bar" id="progress-bar" role="progressbar" aria-valuemin="0" aria-valuemax="100" style="width:0%">
                          <span  id="status"></span>
                          </div>
                      </div>

                      <div class="image-upload-wrap">
                        <input type="text" hidden="1" name="id_perkutut" value="<?=$id?>">
                        <input class="file-upload-input" type='file' id="gam" name="gambar" required="1" onchange="readURL(this);" accept="image/*" />
                        <div class="drag-text">
                          <h3>Drag and drop a file or select add Image</h3>
                        </div>
                      </div>
                      <div class="file-upload-content">
                        <img class="file-upload-image" src="#" alt="your image" />
                        <div class="image-title-wrap">
                          <button type="button" onclick="removeUpload()" class="remove-image">Remove <span class="image-title">Uploaded Image</span></button>
                        </div>
                      </div>
                    </div>

                    </div>
                  <div class="modal-footer">
                      <button class="btn btn-success" onclick="uploadGam()" type="submit"> Simpan&nbsp;</button>
                      <button type="button" class="btn btn-warning" data-dismiss="modal"> Batal</button>
                  </div>
                 </form>
ini tambahan script untuk loading progress dan disini kemungkinan data yang duplicat
<script>

  function uploadGam() {
      var file = document.getElementById("gam").files[0];
      var formdata = new FormData();
      formdata.append("gambar", file);
      var ajax = new XMLHttpRequest();
      ajax.upload.addEventListener("progress", progressUpload, false);
      ajax.open("POST", "<?php echo base_url('Perkutut/tambah_galeri_pk');?>", true);
      ajax.send(formdata);
  }

  function progressUpload(event){
      var percent = (event.loaded / event.total) * 100;
      document.getElementById("progress-bar").style.width = Math.round(percent)+'%';
      document.getElementById("status").innerHTML = Math.round(percent)+"% Tunggu sebentar!!!";
  	if(event.loaded==event.total){
  		redirect('Perkutut/galeri_perkutut');
  	}
  }

  </script>

ketika saya hapus method dan action di form karena di script sudah ada script yang mengirim data ke controller tapi tidak akan bisa terkirim, tetapi jika saya kasih method dan action di form data terkirim dan file yang terupload di folder patch yg disimpan jadi ke duplicat.Screenshot-6.jpgScreenshot_6.jpg 35.61 KBScreenshot-7.jpgScreenshot_7.jpg 40.68 KB
avatar akbarimawandwicahya_google

@akbarimawandwicahya_google

11 Kontribusi 2 Poin

Login untuk menanggapi


Jawaban Terpilih

Solved untuk thread ini, dengan di var_dump satu persatu
avatar akbarimawandwicahya_google

@akbarimawandwicahya_google

11 Kontribusi 2 Poin

Jawaban

Solved untuk thread ini, dengan di var_dump satu persatu
avatar akbarimawandwicahya_google

@akbarimawandwicahya_google

11 Kontribusi 2 Poin

Login untuk menanggapi


Login untuk gabung berdiskusi