/**
  * Creates a new Documento model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate($idcandidato)
 {
     $model = new Documento();
     $model->candidato_idcandidato = $idcandidato;
     $currDate = Date('d-m-Y H:i');
     $docName = $model->candidato_idcandidato . "-" . $currDate;
     $model->link_documento = 'arquivos/' . $docName . "." . "pdf";
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         $model->file = UploadedFile::getInstance($model, 'file');
         $model->file->saveAs($model->link_documento);
         return $this->redirect(array('candidato/update', 'id' => $model->candidato_idcandidato));
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Esempio n. 2
0
 public function actionCargar()
 {
     // set_time_limit(0);
     $tiempo_de_inicio = microtime(true);
     $model = new Documento();
     if ($model->load(Yii::$app->request->post())) {
         $model->docFile = UploadedFile::getInstances($model, 'docFile');
         foreach ($model->docFile as $i => $file) {
             $documento = new Documento();
             // $documento->id_persona = $model->id_persona;
             $documento->direccion_archivo = $file->baseName . '.' . $file->extension;
             $path = Yii::$app->basePath . '/web/imagenes/' . $documento->direccion_archivo;
             // $documento->nombre_documento = $file->baseName;
             $documento->fecha_creacion = date('Y-m-d H:i:s');
             $documento->save();
             $file->saveAs($path);
         }
         $tiempo_fin = microtime(true);
         $mensaje = "Tiempo empleado para cargar" . count($model->docFile) . " tuplas: " . ($tiempo_fin - $tiempo_de_inicio);
         //return $this->render('Tiempo',['mensaje' =>$mensaje]);
         $this->redirect(['index', 'mensaje' => $mensaje]);
     } else {
         return $this->render('cargar', ['model' => $model]);
     }
 }