<div class="panel-heading"> <h4 class="panel-title"> <a data-toggle="collapse" data-toggle="collapse" data-parent="#accordion" href="#collapseThree"> 自定义上上传 </a> </h4> </div> <div id="collapseThree" class="panel-collapse collapse<?php echo $__type === "{user_upload}" ? " in" : ""; ?> "> <div class="panel-body"> <p class="well well-sm text-warning">自己上传图片到服务器上,然后显示你的个性头像。建议上传400*400以上的图片,网站会将图片压缩到此尺寸。</p> <blockquote> <?php $u_a = \ULib\Avatar::upload_avatar(login_user()); if (!empty($u_a)) { ?> <p><img class="img-rounded" src="<?php echo $u_a; ?> ?rand=<?php echo time(); ?> " alt="avatar" width="200" height="200"></p> <small>当前上传的头像</small> <?php } else { ?> <small>当前未上传图片到服务器</small> <?php
/** * 修改头像类型 * @param User $user * @param string $type */ public function edit_avatar($user, $type) { $list = ['{default}', '{gravatar}', '{site_avatar}', '{user_upload}']; $type = strtolower($type); if (!in_array($type, $list)) { $this->throwMsg(-14); } if ($type === "{user_upload}") { lib()->load('Avatar'); $avatar = Avatar::upload_avatar($user); if (empty($avatar)) { $this->throwMsg(-15); } } $user->set(['avatar' => $type]); }
public function user_avatar_upload() { try { $this->throwMsgCheck('is_post', 'is_login'); lib()->load("UserControl"); $uc = new UserControl(); $uc->upload_avatar(login_user()); $this->rt_msg['content'] = Avatar::upload_avatar(login_user()); if (!req()->is_ajax()) { header("Location: " . $_SERVER['HTTP_REFERER']); } $this->rt_msg['status'] = true; } catch (\Exception $ex) { $this->rt_msg['msg'] = $ex->getMessage(); $this->rt_msg['code'] = $ex->getCode(); } }