Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function ekstrakdata() {
- $config['upload_path'] = './temp_sync/dataoperator/';
- $config['allowed_types'] = 'zip';
- $config['max_size'] = '0';
- $config['max_width'] = '0';
- $config['max_height'] = '0';
- $this->load->library('upload');
- $this->upload->initialize($config);
- $upload = $this->upload->do_upload('zipfile');
- $upload_data = $this->upload->data();
- // print_r($upload_data);
- $file_name = $upload_data['full_path']; // File Full Path
- $nama_file = $upload_data['raw_name'];
- $json_file = $upload_data['raw_name'].'.json'; // JSON File
- $zip = new ZipArchive;
- if ($zip->open($file_name) === TRUE) {
- // Buat Folder jika belum Ada
- if (!file_exists('./temp_sync/dataoperator/data_ekstrak/'.$nama_file)) {
- mkdir('./temp_sync/dataoperator/data_ekstrak/'.$nama_file, 0755, true);
- } else {
- // Delete Folder Lama
- $src = './temp_sync/dataoperator/data_ekstrak/'.$nama_file;
- $dir = opendir($src);
- while(false !== ( $file = readdir($dir)) ) {
- if (( $file != '.' ) && ( $file != '..' )) {
- if ( is_dir($src . '/' . $file) ) {
- delete_dir($src . '/' . $file);
- }
- else {
- unlink($src . '/' . $file);
- }
- }
- }
- closedir($dir);
- rmdir($src);
- // Buat Folder baru lagi
- mkdir('./temp_sync/dataoperator/data_ekstrak/'.$nama_file, 0755, true);
- }
- $zip->extractTo('./temp_sync/dataoperator/data_ekstrak/'.$nama_file);
- $zip->close();
- } else {
- echo 'Ekstrak ZIP Gagal.';
- }
- $url = base_url("temp_sync/dataoperator/data_ekstrak/".$nama_file.'/'.$json_file);
- $curl = curl_init();
- curl_setopt($curl, CURLOPT_URL, $url);
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($curl, CURLOPT_HEADER, false);
- $curl_response = curl_exec($curl);
- curl_close($curl);
- $data = json_decode($curl_response);
- print_r($data);
- $data = array(
- 'test_nik' => trim($data->nik),
- 'test_no_rtlh' => trim($data->no_rtlh),
- 'test_nama' => trim($data->alias)
- );
- $this->db->insert('rtlh_test_zip', $data);
- unlink($file_name); // Delete Zip
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement