Ejemplo n.º 1
0
 public function actionAvatar()
 {
     $session = Yii::$app->getSession();
     $model = new UploadForm();
     $suffix = 'png';
     $me = Yii::$app->getUser()->getIdentity();
     $model->file = UploadedFile::getInstance($model, 'file');
     if ($model->file && $model->validate()) {
         $name = $me->id;
         $myId = strtolower(Util::shorturl($me->id));
         $savePath = 'avatar/' . substr($myId, 0, 1) . '/' . substr($myId, 1, 1);
         $avatar = $savePath . '/' . $name . '_{size}.' . $suffix . '?m=' . time();
         $this->resizeAvator($this->resizes, $model->file->tempName, $savePath, $name, $suffix);
         $me->avatar = $avatar;
         $me->save(false);
         $session->setFlash('setAvatarOK', '头像设定成功,显示可能有延迟,请刷新。');
     } else {
         $session->setFlash('setAvatarNG', '头像设定失败');
     }
     return $this->redirect(['user/setting', '#' => 'avatar']);
 }
Ejemplo n.º 2
0
 public function uploadAvatar($uid)
 {
     $suffix = 'png';
     if ($this->file && $this->validate()) {
         $name = $uid;
         $myId = strtolower(Util::shorturl($uid));
         $savePath = 'avatar/' . substr($myId, 0, 1) . '/' . substr($myId, 1, 1);
         //			$this->resizeAvator( $this->_avatarSizes, $this->file->tempName, $savePath, $name, $suffix);
         Upload::uploadAvatar($this->file->tempName, $savePath, $name, $suffix);
         return $savePath . '/' . $name . '_{size}.' . $suffix . '?m=' . time();
     }
     return false;
 }