Created
August 15, 2019 04:19
-
-
Save mdestafadilah/e261f5c4cd33f89a4c705f7a56c45650 to your computer and use it in GitHub Desktop.
Fungsi Upload
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function disposisi_upload() | |
{ | |
$this->load->library(array('PHPExcel','PHPExcel/IOFactory')); | |
if ($this->input->post('save')) { | |
$type = explode('.', $_FILES["import"]["name"]); // data file | |
$type = strtolower($type[count($type)-1]); // data type like .jpg | |
// exit(dump($type)); | |
$inputFileName = "./assets/upload/".uniqid(rand()).'.'.$type; // hash unik | |
if(in_array($type, array("xls", "xlsx"))) { | |
if(is_uploaded_file($_FILES["import"]["tmp_name"])) { | |
if(move_uploaded_file($_FILES["import"]["tmp_name"],$inputFileName)) { | |
// Read your Excel workbook | |
try { | |
$inputFileType = IOFactory::identify($inputFileName); | |
$objReader = IOFactory::createReader($inputFileType); | |
$objPHPExcel = $objReader->load($inputFileName); | |
} catch(Exception $e) { | |
die('Error loading file "'.pathinfo($inputFileName,PATHINFO_BASENAME).'": '.$e->getMessage()); | |
} | |
// Get worksheet dimensions | |
$sheet = $objPHPExcel->getSheet(0); | |
$highestRow = $sheet->getHighestRow(); | |
$highestColumn = $sheet->getHighestColumn(); | |
// Loop through each row of the worksheet in turn | |
for ($row = 2; $row <= $highestRow; $row++) { // Read a row of data into an array | |
$rowData = $sheet->rangeToArray('A' . $row . ':' . $highestColumn . $row, | |
NULL, | |
TRUE, | |
FALSE); | |
// Insert row data array into your database of choice here | |
$data = array( | |
"nama" => $rowData[1][3], | |
"kode_org" => $rowData[1][2], | |
); | |
// exit(dump($rowData[0][1])); | |
$this->db->insert("sdm_master_jabatan_detail",$data); // exit(show_last_query()); | |
} | |
echo "Import Success, tunggu sebentar.."; | |
} | |
} | |
} | |
} | |
$this->setFlash('Data eksel berhasil diimport!', 'alert-success'); | |
redirect('office/upload_disposisi','refresh'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment