/** * 保存头像 * @param $url * @return string */ public function saveAvatar($url) { //a.php/1/linkAccess/thumbnail?key=38ezrz&size=256x256&path=/align-right.png //save image to avatar folder,file name is user_uuid.png $user = MiniUser::getInstance()->getUser($this->user["id"]); $avatarName = MiniUtil::getRandomName(8) . ".png"; $savePath = THUMBNAIL_TEMP . "avatar"; $path = $savePath . '/' . $avatarName; if (!file_exists($savePath)) { mkdir($savePath); } file_put_contents($path, file_get_contents($url)); //save to db MiniUserMeta::getInstance()->updateMeta($user["id"], "avatar", $avatarName); //保存原始图片,便于其它迷你云节点可显示该图片的缩略图 MiniUserMeta::getInstance()->updateMeta($user["id"], "avatar_url", $url); return MiniHttp::getMiniHost() . "assets/thumbnails/avatar/" . $avatarName; }