Advertisement
jamboljack

Ekstrak ZIP

Nov 30th, 2017
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.38 KB | None | 0 0
  1. public function ekstrakdata() {
  2.         $config['upload_path']      = './temp_sync/dataoperator/';
  3.         $config['allowed_types']    = 'zip';
  4.         $config['max_size']         = '0';
  5.         $config['max_width']        = '0';
  6.         $config['max_height']       = '0';
  7.         $this->load->library('upload');
  8.         $this->upload->initialize($config);
  9.  
  10.         $upload         = $this->upload->do_upload('zipfile');
  11.         $upload_data    = $this->upload->data();
  12.         // print_r($upload_data);
  13.         $file_name      = $upload_data['full_path']; // File Full Path
  14.         $nama_file      = $upload_data['raw_name'];
  15.         $json_file      = $upload_data['raw_name'].'.json'; // JSON File
  16.  
  17.         $zip = new ZipArchive;
  18.         if ($zip->open($file_name) === TRUE) {
  19.             // Buat Folder jika belum Ada
  20.             if (!file_exists('./temp_sync/dataoperator/data_ekstrak/'.$nama_file)) {
  21.                 mkdir('./temp_sync/dataoperator/data_ekstrak/'.$nama_file, 0755, true);
  22.             } else {
  23.                 // Delete Folder Lama
  24.                 $src = './temp_sync/dataoperator/data_ekstrak/'.$nama_file;
  25.                 $dir = opendir($src);
  26.                 while(false !== ( $file = readdir($dir)) ) {
  27.                     if (( $file != '.' ) && ( $file != '..' )) {
  28.                         if ( is_dir($src . '/' . $file) ) {
  29.                             delete_dir($src . '/' . $file);
  30.                         }
  31.                         else {
  32.                             unlink($src . '/' . $file);
  33.                         }
  34.                     }
  35.                 }
  36.                 closedir($dir);
  37.                 rmdir($src);
  38.                 // Buat Folder baru lagi
  39.                 mkdir('./temp_sync/dataoperator/data_ekstrak/'.$nama_file, 0755, true);
  40.             }
  41.             $zip->extractTo('./temp_sync/dataoperator/data_ekstrak/'.$nama_file);
  42.             $zip->close();
  43.         } else {
  44.             echo 'Ekstrak ZIP Gagal.';
  45.         }
  46.  
  47.         $url    = base_url("temp_sync/dataoperator/data_ekstrak/".$nama_file.'/'.$json_file);
  48.         $curl   = curl_init();
  49.         curl_setopt($curl, CURLOPT_URL, $url);
  50.         curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  51.         curl_setopt($curl, CURLOPT_HEADER, false);
  52.         $curl_response = curl_exec($curl);
  53.         curl_close($curl);
  54.         $data = json_decode($curl_response);
  55.         print_r($data);
  56.    
  57.         $data = array(              
  58.                 'test_nik'          => trim($data->nik),
  59.                 'test_no_rtlh'      => trim($data->no_rtlh),
  60.                 'test_nama'         => trim($data->alias)
  61.             );
  62.  
  63.         $this->db->insert('rtlh_test_zip', $data);
  64.         unlink($file_name); // Delete Zip
  65.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement