public function actionAvatar() { $fileParts = pathinfo($_FILES['avatar']['name']); if ($_FILES['avatar']['error']) { $this->renderJson([], -1, yii::t('user', 'upload failed')); } if ($_FILES['avatar']['size'] > static::AVATAR_SIZE) { $this->renderJson([], -1, yii::t('user', 'attached\'s size too large')); } if (!in_array(strtolower($fileParts['extension']), \Yii::$app->params['user.avatar.extension'])) { $this->renderJson([], -1, yii::t('user', 'type not allow', ['types' => join(', ', \Yii::$app->params['user.avatar.extension'])])); } $tempFile = $_FILES['avatar']['tmp_name']; $baseName = sprintf('%s-%d.%s', date("YmdHis", time()), rand(10, 99), $fileParts['extension']); $newFile = User::AVATAR_ROOT . $baseName; $urlFile = GlobalHelper::formatAvatar($baseName); $targetFile = sprintf("%s/web/%s", rtrim(\Yii::$app->basePath, '/'), ltrim($newFile, '/')); $ret = move_uploaded_file($tempFile, $targetFile); if ($ret) { $user = User::findOne($this->uid); $user->avatar = $baseName; $ret = $user->save(); } $this->renderJson(['url' => $urlFile], !$ret, $ret ?: yii::t('user', 'update avatar failed')); }
public function actionAvatar() { $fileParts = pathinfo($_FILES['avatar']['name']); if ($_FILES['avatar']['error']) { $this->renderJson([], -1, '上传附件失败'); } if ($_FILES['avatar']['size'] > static::AVATAR_SIZE) { $this->renderJson([], -1, '文件过大'); } if (!in_array(strtolower($fileParts['extension']), \Yii::$app->params['user.avatar.extension'])) { $this->renderJson([], -1, '上传附件失败,附件格式只支持:' . join(', ', \Yii::$app->params['user.avatar.extension'])); } $tempFile = $_FILES['avatar']['tmp_name']; $baseName = sprintf('%s-%d.%s', date("YmdHis", time()), rand(10, 99), $fileParts['extension']); $newFile = GlobalHelper::formatAvatar($baseName); $targetFile = sprintf("%s/web/%s", rtrim(\Yii::$app->basePath, '/'), ltrim($newFile, '/')); $ret = move_uploaded_file($tempFile, $targetFile); if ($ret) { $user = User::findOne($this->uid); $user->avatar = $baseName; $ret = $user->save(); } $this->renderJson(['url' => $newFile], !$ret, $ret ?: '更新头像失败'); }
<a href="#"> 查看所有通知 <i class="icon-arrow-right"></i> </a> </li> --> </ul> </li> <?php } ?> <li class="light-blue"> <a data-toggle="dropdown" href="javascript:;" class="dropdown-toggle"> <img class="nav-user-photo" src="<?php echo GlobalHelper::formatAvatar($user->avatar); ?> "> <span class="user-info" style="top:12px"><?php echo $userName; ?> </span> <i class="icon-caret-down"></i> </a> <ul class="user-menu pull-right dropdown-menu dropdown-yellow dropdown-caret dropdown-close"> <!-- 设置功能暂无 <li> <a href="javascript:;"> <i class="icon-cog"></i> 设置
$sideBarMenus = $this->context->sideBar; } elseif (!empty($this->context->module->menus)) { $sideBarMenus = $this->context->module->menus; } else { $sideBarMenus = [['label' => '用户管理', 'items' => [['label' => '用户列表', 'url' => '/user/list'], ['label' => '添加用户', 'url' => '/user/add']]], ['label' => Yii::t('w', 'menu task list'), 'url' => '/task/index'], ['label' => Yii::t('w', 'menu submit task'), 'url' => '/task/submit'], ['label' => Yii::t('w', 'menu file md5'), 'url' => '/walle/check'], ['label' => Yii::t('w', 'menu config project'), 'url' => '/conf', 'visible' => \Yii::$app->user->identity->role == app\models\User::ROLE_ADMIN]]; } ?> <aside class="main-sidebar"> <section class="sidebar"> <!-- Sidebar user panel --> <div class="user-panel"> <div class="pull-left image"> <!--<img src="<?php echo \app\components\GlobalHelper::formatAvatar(\Yii::$app->user->identity->avatar); ?> " class="img-circle" alt="User Image"/>--> <img src="<?php echo $directoryAsset; ?> /img/user2-160x160.jpg" class="img-circle" alt="User Image"/> </div> <div class="pull-left info"> <?php /* <p><?= \Yii::$app->user->identity->username ?></p> */ ?> <p> 你好,<?php echo \Yii::$app->user->identity->username; ?> </p>