...
|
...
|
@@ -209,6 +209,7 @@ class Login extends Base |
|
|
public function getuserdata(){
|
|
|
$username=$this->request->param("username");
|
|
|
$avatar=$this->request->param("avatar");
|
|
|
$avatar=$this->uploadBase64($avatar);
|
|
|
$user_id=$this->auth->id;
|
|
|
Db::name("user")
|
|
|
->where("id", $user_id)
|
...
|
...
|
@@ -219,5 +220,27 @@ class Login extends Base |
|
|
]);
|
|
|
$this->success("请求成功");
|
|
|
}
|
|
|
public function uploadBase64($base64Str)
|
|
|
{
|
|
|
|
|
|
// 将Base64字符串转换为文件并保存
|
|
|
if ($base64Str) {
|
|
|
// 获取Base64字符串的类型
|
|
|
preg_match('/^data:image\/(.*);base64/', $base64Str, $match);
|
|
|
$ext = $match[1];
|
|
|
|
|
|
// 生成文件名
|
|
|
$fileName = uniqid() . '.' . $ext;
|
|
|
// 获取项目根目录
|
|
|
//$rootPath = root_path();
|
|
|
|
|
|
// 保存文件路径
|
|
|
$filePath = ROOT_PATH . 'public/uploads/' . $fileName;
|
|
|
|
|
|
// 保存文件
|
|
|
file_put_contents($filePath, base64_decode(str_replace($match[0], '', $base64Str)));
|
|
|
return "uploads/".$fileName;
|
|
|
|
|
|
}
|
|
|
}
|
|
|
} |
|
|
\ No newline at end of file |
...
|
...
|
|