Commit 2f2cf155 authored by hujun's avatar hujun

上传用户头像

parent 1ff32af9
...@@ -362,4 +362,39 @@ class Member extends Basic ...@@ -362,4 +362,39 @@ class Member extends Basic
$data['msg'] = ''; $data['msg'] = '';
return $this->response($data['status'], $data['msg'], $data['data']); return $this->response($data['status'], $data['msg'], $data['data']);
} }
/**
* 上传头像
*
* @return \think\Response
*/
public function uploadHeadImg() {
$data['status'] = 101;
$data['msg'] = '';
$data['data'] = '';
$file = request()->file('image');
if($file){
$path = ROOT_PATH . 'public' . DS . 'static'. DS . 'head_portrait';
$info = $file->validate(['size'=>512000,'ext'=>'jpg,png']) //限制500KB
->move($path);
if($info){
$img_path = $info->getSaveName();
$static_path = $path.DS.$img_path;
$image = \think\Image::open($static_path);
$image->thumb(500, 500)->save($static_path); //生成缩略图
$data['status'] = 200;
$data['msg'] = '上传成功';
$data['data'] = ['file_name' => $info->getFilename()];
}else{
// 上传失败获取错误信息
$data['msg'] = $file->getError();
}
} else {
$data['msg'] = '没有该文件';
}
return $this->response($data['status'], $data['msg'], $data['data']);
}
} }
...@@ -99,6 +99,7 @@ Route::group('api', [ ...@@ -99,6 +99,7 @@ Route::group('api', [
//post member //post member
'login' => [ 'api/member/login', [ 'method' => 'post' ] ], //c端登陆 'login' => [ 'api/member/login', [ 'method' => 'post' ] ], //c端登陆
'register' => [ 'api/member/register', [ 'method' => 'post' ] ], //注册|邀请注册|编辑 'register' => [ 'api/member/register', [ 'method' => 'post' ] ], //注册|邀请注册|编辑
'uploadHeadImg' =>['api/member/uploadHeadImg',['method'=>'post']], //头像上传
// shop // shop
'shopList' => [ 'api/shop/getShopList', [ 'method' => 'post' ] ], 'shopList' => [ 'api/shop/getShopList', [ 'method' => 'post' ] ],
...@@ -123,8 +124,6 @@ Route::group('api', [ ...@@ -123,8 +124,6 @@ Route::group('api', [
//AttentionShop //AttentionShop
'addOrUpdateAttention' => [ 'api/AttentionShop/addOrUpdateAttention', [ 'method' => 'post|get' ] ], 'addOrUpdateAttention' => [ 'api/AttentionShop/addOrUpdateAttention', [ 'method' => 'post|get' ] ],
'attentionList' => [ 'api/AttentionShop/attentionList', [ 'method' => 'post | get' ] ], 'attentionList' => [ 'api/AttentionShop/attentionList', [ 'method' => 'post | get' ] ],
]); ]);
Route::miss('api/index/miss');//处理错误的url Route::miss('api/index/miss');//处理错误的url
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment