Esempio n. 1
0
 /**
  * Guarda la foto subida
  */
 public static function actionchangePic()
 {
     $transaction = Yii::app()->db->beginTransaction();
     try {
         $model = ModelUser::model()->findbyPk(Yii::app()->user->id_user);
         $file = CUploadedFile::getInstance($model, 'pic_file');
         if (trim($file) != "") {
             $urlcarpetaFile = Params::Server()->urlImagesUser . Yii::app()->user->id_user . '/';
             $extensionfile = Files::getNombreExtensionFile($file->name);
             $nombrefile = rand(1, 100) . '_' . strtotime("now");
             $urlimagen = $urlcarpetaFile . "/" . $nombrefile . "." . $extensionfile['extension'];
             $model->pic_file = $nombrefile . '.' . $extensionfile['extension'];
             if (!$model->update()) {
                 $er = "<pre>" . json_encode($model->getErrors()) . "</pre>";
                 throw new Exception("No se pudo guardar la información por : {$er}");
             }
             $file->saveAs($urlimagen);
         }
         $transaction->commit();
         Yii::app()->request->redirect(Yii::app()->baseUrl . '/user/account');
     } catch (Exception $ex) {
         $transaction->rollBack();
         $c = new Controller('site');
         $c->render('application.views.site.error', $ex);
     }
 }