Browse Source

修改用户头像

wzh 5 năm trước cách đây
mục cha
commit
abc6e61a9e
1 tập tin đã thay đổi với 38 bổ sung0 xóa
  1. 38 0
      api/application/controllers/User.php

+ 38 - 0
api/application/controllers/User.php

@@ -378,5 +378,43 @@ class User extends Base_Controller{
 
 		exit(json_result('0000',$this->response['0000'],array()));
 	}
+
+	// 修改用户头像
+    public function update_avatar(){
+
+        $path = '../upload/image';
+        $config['file_name'] = md5(uniqid());   // 设置图片名字
+       
+        if (!file_exists($path)) {
+            mkdir($path);
+        }
+        $config['upload_path']      = $path.'/';   // 设置图片上传路径
+        $config['allowed_types']    = '*';  // 设置图片上传格式
+        $config['max_size']     = 10240;   // 设置文件上传大小
+        
+        $this->load->library('upload', $config);
+
+        if ( ! $this->upload->do_upload('file'))
+        {
+            $error = array('error' => $this->upload->display_errors('',''));
+
+            // if (empty($this->version)) {
+                // $data = array('error'=>transfer_error_tips($error['error']));
+            // }else{
+                $data = array('error'=>$error['error']);
+            // }
+            exit(json_result('0012',$this->response['0012'],$data));
+        }
+        else
+        {
+            $data = $this->upload->data();
+
+            $imagePath = '/upload/image/'.$data['file_name'];
+            
+            $id = $this->get_user_info('id');
+            $this->User_model->update(['avatar'=>$imagePath],['id'=>$id]);
+            exit(json_result('0000',$this->response['0000']));
+        }
+    }
 }
 ?>