Commit 4c8c24b4 authored by hujun's avatar hujun

删除上一次上传的头像

parent 606b762d
...@@ -390,21 +390,23 @@ class Member extends Basic ...@@ -390,21 +390,23 @@ class Member extends Basic
$info = $file->validate(['size'=>512000,'ext'=>'jpg,png']) //限制500KB $info = $file->validate(['size'=>512000,'ext'=>'jpg,png']) //限制500KB
->move($path); ->move($path);
if($info){ if($info){
$img_path = $info->getSaveName(); //生成的图片路径 if ($this->userId) {
$static_path = $path.DS.$img_path; //生成图片的绝对路径 $user = new Users();
$image = \think\Image::open($static_path); $user_data = $user->field('user_pic')->where('id',$this->userId)->find();
$image->thumb(500, 500)->save($static_path); //生成缩略图 @unlink($path.DS.$user_data->user_pic); //删除原来的图片
$img_path = $info->getSaveName(); //生成的图片路径
//更新用户信息 $static_path = $path.DS.$img_path; //生成图片的绝对路径
$user = new Users(); $image = \think\Image::open($static_path);
$user->update([ $image->thumb(500, 500)->save($static_path); //生成缩略图
'id' => $this->userId,
'user_pic' => $img_path //更新用户信息
]); $user_data->user_pic = $img_path;
$user_data->save();
$data['status'] = 200;
$data['msg'] = '上传成功';
$data['data'] = ['file_name' => HEADERIMGURL . $img_path];
}
$data['status'] = 200;
$data['msg'] = '上传成功';
$data['data'] = ['file_name' => HEADERIMGURL . $img_path];
}else{ }else{
// 上传失败获取错误信息 // 上传失败获取错误信息
$data['msg'] = $file->getError(); $data['msg'] = $file->getError();
......
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