Sebuahhobi98

file_upload

Mar 12th, 2022 (edited)
353
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.45 KB | None | 0 0
  1.         $foto['allowed_types']   = 'jpg|png|jpeg';
  2.         $foto['detect_mime']     = TRUE;
  3.         $foto['overwrite']       = TRUE;
  4.         $foto['file_name']       = str_replace(' ', '-', $this->input->post('nama',TRUE)).'_'.str_replace(' ', '-', tgl_indo(date('Y-m-d')));
  5.         if($this->input->post('j_k') == 'L'){
  6.             $foto['upload_path']     = './assets/upload/ikhwan';
  7.         }else if($this->input->post('j_k') == 'P'){
  8.             $foto['upload_path']     = './assets/upload/akhwat';
  9.         }
  10.  
  11.         $this->load->library('upload', $foto);
  12.         $fileExt = pathinfo($_FILES["foto"]["name"], PATHINFO_EXTENSION);
  13.  
  14.         if(! $this->upload->do_upload("foto")){
  15.             $this->data['foto_error'] = 0;
  16.             $this->data['foto']       = $this->upload->display_errors('','');
  17.         } else {
  18.             $this->data['foto_error'] = 1;
  19.             $this->data['foto']       = $this->upload->data('file_name');
  20.         }
  21.  
  22.             $foto_ktm['allowed_types']   = 'jpg|png|jpeg';
  23.             $foto_ktm['overwrite']       = TRUE;
  24.             $foto_ktm['file_name']       = str_replace(' ', '-', $this->input->post('nama',TRUE)).'_'.str_replace(' ', '-', tgl_indo(date('Y-m-d')));
  25.             if($this->input->post('j_k') == 'L'){
  26.                 $foto_ktm['upload_path']     = './assets/upload/ikhwan/ktm';
  27.             }else if($this->input->post('j_k') == 'P'){
  28.                 $foto_ktm['upload_path']     = './assets/upload/akhwat/ktm';
  29.             }
  30.             $this->upload->initialize($foto_ktm);
  31.             if(! $this->upload->do_upload("foto_ktm")){
  32.                 $this->data['foto_ktm_error'] = 0;
  33.                 $this->data['foto_ktm']       = $this->upload->display_errors('','');
  34.             } else {
  35.                 $this->data['foto_ktm_error'] = 1;
  36.                 $this->data['foto_ktm']       = $this->upload->data('file_name');
  37.             }
  38.  
  39.             if (isset($_FILES['sertifikat_ldik']['name']) && !empty($_FILES['sertifikat_ldik']['name'])) {
  40.                 $sertifikat_ldik['allowed_types']   = '*';
  41.                 $sertifikat_ldik['overwrite']       = TRUE;
  42.                 $sertifikat_ldik['file_name']       = str_replace(' ', '-', $this->input->post('nama',TRUE)).'_'.str_replace(' ', '-', tgl_indo(date('Y-m-d')));
  43.  
  44.                 if($this->input->post('j_k') == 'L'){
  45.                     $sertifikat_ldik['upload_path']     = './assets/upload/ikhwan/sertifikat';
  46.                 }else if($this->input->post('j_k') == 'P'){
  47.                     $sertifikat_ldik['upload_path']     = './assets/upload/akhwat/sertifikat';
  48.                 }
  49.                 $this->upload->initialize($sertifikat_ldik);
  50.                 if(! $this->upload->do_upload("sertifikat_ldik")){
  51.                     $this->data['sertifikat_error'] = 0;
  52.                     $this->data['sertifikat']       = $this->upload->display_errors('','');
  53.                 } else {
  54.                     $this->data['sertifikat_error'] = 1;
  55.                     $this->data['sertifikat']       = $this->upload->data('file_name');
  56.                 }  
  57.             }
  58.  
  59.  
  60.             if ($this->form_validation->run() == FALSE || $this->input->post('noHP') === $this->input->post('noHP_Ayah') || $this->data['foto_error'] == 0 || $this->data['foto_ktm_error'] == 0 || $this->data['sertifikat_error'] == 0) {
  61.                 $data = array(
  62.                     'foto_' => $fileExt,
  63.                 );
  64.  
  65.                 if($this->data['sertifikat_error'] == 0){
  66.                     $data['sertifikat_ldik'] = $this->data['sertifikat'];
  67.                 }
  68.  
  69.                 if($this->data['foto_error'] == 0){
  70.                     $data['foto'] = $this->data['foto'];
  71.                 }
  72.             }
Add Comment
Please, Sign In to add comment