Esempio n. 1
0
 public function actionUpdateProfileImage()
 {
     if (Yii::app()->request->isAjaxRequest) {
         if (isset($_POST['crop'])) {
             $fileName = uniqid() . '.png';
             ActionClass::deleteFile('default/img/users', Yii::app()->user->profile_img);
             $img = $_POST['image'];
             $upload_dir = 'themes/default/img/users/';
             $upload = ActionClass::uploadBase64File($img, $upload_dir, $fileName);
             if ($upload) {
                 Users::model()->updateByPk(Yii::app()->user->id, array('profile_img' => $fileName));
                 echo json_encode(['success' => true, 'message' => 'Successfuly uploaded', 'file' => Yii::app()->theme->baseUrl . '/img/users/' . $fileName]);
                 Yii::app()->end();
             }
             echo json_encode(['success' => false, 'message' => 'Missing crop index']);
             Yii::app()->end();
         }
     }
     return $this->redirect('/');
 }