/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer $id the ID of the model to be loaded * @return EamsFilesImport the loaded model * @throws CHttpException */ public function loadModel($id) { $model = EamsFilesImport::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
public function actionReceiveExternalData($import_type = NULL) { if (Yii::app()->request->isPostRequest) { $files = $_FILES; $targetDir = Yii::getPathOfAlias('webroot') . '/uploads/imports/'; foreach ($files as $key => $file) { $name = $file['name']; $tempName = $file['tmp_name']; $type = $file['type']; $error = $file['error']; $size = $file['size']; if ($error == 0) { $targetFile = $targetDir . basename($name); $fileFormat = pathinfo($targetFile, PATHINFO_EXTENSION); if (!file_exists($targetFile) && preg_match('/(xls|xlsx)/i', $fileFormat)) { move_uploaded_file($tempName, $targetFile); $fileImportModel = new EamsFilesImport(); $fileImportModel->name = $name; $fileImportModel->import_key = $import_type; $fileImportModel->mime_type = $type; $fileImportModel->file_extension = $fileFormat; $fileImportModel->file_size = $size; $fileImportModel->date_created = date('Y-m-d H:i:s'); $fileImportModel->save(); } else { echo "File already exists"; } } } } }