public function actionImport4($fortythree, $upload_date, $upload_time) { ini_set('max_execution_time', 0); //$ubuntu_path = "/var/lib/mysql/fortythree/"; $rootpath = \Yii::getAlias('@webroot') . "/fortythree/"; $filefortythree = $rootpath . $fortythree; $file_size = number_format(filesize($filefortythree) / (1024 * 1024), 3); $file_size = strval($file_size); $zip = new \ZipArchive(); if ($zip->open($filefortythree) === TRUE) { $zip->extractTo($rootpath); $zip->close(); } //rename($path . $oldname, $path . $fortythree); unlink("{$rootpath}{$fortythree}"); $folder_with_ext = explode('.', $fortythree); $folder_without_ext = $folder_with_ext[0]; $full_dir = "{$rootpath}/{$folder_without_ext}"; $dir = opendir($full_dir); $cfmodel = new SysCountImport(); $cfmodel->import_date = date('YmdHis'); $cfmodel->filename = $fortythree; $cfmodel->upload_date = $upload_date; $cfmodel->upload_time = $upload_time; while (($file = readdir($dir)) !== false) { if ($file !== "." && $file !== "..") { $p = pathinfo($file); $ftxt = $p['filename']; $ftxt = strtolower($ftxt); $ext = $p['extension']; if (strtolower($ext) == 'txt' && $ftxt !== 'office') { $transaction = \Yii::$app->db->beginTransaction(); try { $sql = "LOAD DATA LOCAL INFILE '{$rootpath}{$folder_without_ext}/{$file}'"; $sql .= " REPLACE INTO TABLE {$ftxt}"; $sql .= " FIELDS TERMINATED BY '|' LINES TERMINATED BY '\r\n' IGNORE 1 LINES"; $count = \Yii::$app->db->createCommand($sql)->execute(); $transaction->commit(); } catch (Exception $e) { $transaction->rollBack(); } if ($cfmodel->hasAttribute($ftxt)) { $cfmodel->setAttribute($ftxt, $count); } } } } $cfmodel->save(); $upload = new Uploadallcdc(); $upload->file_name = $fortythree; $upload->file_size = $file_size; $fff = explode('_', $fortythree); $upload->hospcode = $fff[1]; $upload->upload_date = date('Ymd'); $upload->upload_time = date('His'); $upload->note2 = 'OK'; $upload->note3 = 'import all'; $upload->save(); $up = Uploadallcdc::findOne(['file_name' => $fortythree]); if ($up) { $up->note2 = 'OK'; $up->note3 = 'import all'; $up->update(); } closedir($dir); $dir = opendir($full_dir); while (($file = readdir($dir)) !== false) { if ($file !== "." && $file !== "..") { if ($file !== "." && $file !== "..") { unlink("{$rootpath}{$folder_without_ext}/{$file}"); } } } closedir($dir); rmdir("{$rootpath}{$folder_without_ext}"); return $fortythree; }
/** * Finds the Uploadallcdc model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Uploadallcdc the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Uploadallcdc::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }