/**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new EamsFilesImport();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['EamsFilesImport'])) {
         $model->attributes = $_POST['EamsFilesImport'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }
Beispiel #2
0
 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";
                 }
             }
         }
     }
 }