Advertisement
ronikuchan

upload

Sep 12th, 2019
361
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.29 KB | None | 0 0
  1. public function uploadImage($newNamaFile, $dirUpload, $postName)
  2.     {
  3.         $config['upload_path']          = './resources/img/syarat_calon_mitra/'.$dirUpload;
  4.         $config['allowed_types']        = 'jpg';
  5.         $config['file_name']            = $newNamaFile;
  6.         $config['overwrite']            = true;
  7.         $config['max_size']             = 5120; // 1MB
  8.  
  9.         $this->load->library('upload', $config);
  10.  
  11.         if ($this->upload->do_upload($postName)) {
  12.             return true;
  13.         }else{
  14.             $error = array('error' => $this->upload->display_errors());
  15.             if(preg_match("/filetype/i", $error['error'])) {
  16.                 $data['error'] = 'Silahkan Pilih File .JPG';
  17.             } else if(preg_match("/size/i", $error['error'])){
  18.                 $data['error'] = 'Max 5MB';
  19.             }
  20.             $this->form_validation->set_rules($postName, '', 'callback_cek_file2');
  21.         }
  22.     }
  23.  
  24. function add(){
  25. if (!empty($_FILES['foto_ktp']['name'])) {
  26.                 $namaFileEKTP      = $_FILES['foto_ktp']['name'];
  27.                 $namaSementaraEKTP = $_FILES['foto_ktp']['tmp_name'];
  28.                 $newNamaFileEKTP   = $this->input->post('nomor_ktp') . $_FILES['foto_ktp']['name'];
  29.                 $file_extEKTP      = pathinfo($namaFileEKTP, PATHINFO_EXTENSION);
  30.                 $dirUploadEKTP     = "ektp/";
  31.                 $postNameEKTP      = 'foto_ktp';
  32.  
  33.                 $upload = $this->uploadImage($newNamaFileEKTP, $dirUploadEKTP, $postNameEKTP);
  34.                 if ($upload == 1) {
  35.                     $params['foto_ktp'] = $newNamaFileEKTP;
  36.                 }
  37.             }
  38. if (!empty($_FILES['foto_kk']['name'])) {
  39.                 $namaFileKK      = $_FILES['foto_kk']['name'];
  40.                 $namaSementaraKK = $_FILES['foto_kk']['tmp_name'];
  41.                 $newNamaFileKK   = $this->input->post('nomor_ktp') . $_FILES['foto_kk']['name'];
  42.                 $file_ext        = pathinfo($namaFileKK, PATHINFO_EXTENSION);
  43.                 $dirUploadKK     = "kartu_keluarga/";
  44.                 $postNameKK      = 'foto_kk';
  45.                
  46.                 $upload = $this->uploadImage($newNamaFileKK, $dirUploadKK, $postNameKK);
  47.                 if ($upload == 1) {
  48.                     $params['foto_kk'] = $newNamaFileKK;
  49.                 }
  50.             }
  51.  
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement