Ejemplo n.º 1
0
 /**
  * Creates a new Uploadallcdc model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     //set_time_limit(0);
     //ini_set('max_execution_time', 1800);//ตั้งค่า php.ini
     //ini_set('post_max_size', '64M');
     //ini_set('upload_max_filesize', '64M');
     $model = new Uploadallcdc();
     if ($model->load(Yii::$app->request->post())) {
         $upfile = UploadedFile::getInstance($model, 'file');
         if (!$upfile) {
             return $this->render('create', ['model' => $model]);
         }
         $hos = '-';
         $hospcode = explode("_", $upfile->baseName);
         if (strtoupper($hospcode[1]) === 'F43') {
             $hos = $hospcode[2];
         } else {
             $hos = $hospcode[1];
         }
         $model->hospcode = $hos;
         $newname = $upfile->baseName . "." . $upfile->extension;
         $model->file_name = $newname;
         $model->file_size = strval(number_format($upfile->size / (1024 * 1024), 3));
         $model->note1 = $upfile->baseName;
         $model->note2 = 'รอนำเข้า';
         $model->save();
         $path = './fileupload/';
         $pathbackup = './fileuploadbackup/';
         $upfile->saveAs($path . $newname);
         copy($path . $newname, $pathbackup . $newname);
         $ubuntu_path = "/var/lib/mysql/fileupload/";
         if (strncasecmp(PHP_OS, 'WIN', 3) !== 0) {
             //copy($path . $newname, $ubuntu_path . $newname);
         }
         return $this->redirect(['view', 'id' => $model->id]);
         //}
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }