application/modules/api_v1/controllers/User.php
//Update user (buyer) profile image
Update user (buyer) profile image
Update user ( buyer ) profile image
function update_avatar_post(){
        $this->check_service_auth(); 
        $user_id = $this->authData->userID;
        $headerInfo = $this->request_headers; 
        $authToken = $this->get_bearer_token();  
        $profile_image=NULL;
        if(!empty($_FILES['profile_picture']['name'])){
            $this->load->model('image_model'); 
            $upload_img = $this->image_model->upload_image('profile_picture', 'profile');
            if(array_key_exists("error",$upload_img) && !empty($upload_img['error'])){
                $this->error_response(strip_tags($upload_img['error'])); 
            }
            if(array_key_exists("image_name", $upload_img)){
                $profile_image = $upload_img['image_name'];
            }
            $getAvatar = $this->common_model->get_field_value(USERS, array('userID' => $user_id),'avatar'); 
            $update = $this->common_model->updateFields(USERS,array('avatar' =>$profile_image,'is_avatar_url' => '1'), array('userID' => $user_id));
            if($update === TRUE){
                $this->load->model('auth_model');
                if($getAvatar != NULL){
                    $imgPath = 'profile';
                    $del = $this->image_model->delete_image($imgPath,$getAvatar);
                }
                $userDetail = $this->auth_model->userInfo(array('userID' => $user_id, 'user_type' =>'buyer', 'device_id' => $headerInfo['device-id']));
                $userDetail->authtoken = $authToken;
                $this->success_response(get_response_message(144),['user_detail' => $userDetail,'business_info' => (object)[]]);
            }
            $this->error_response(get_response_message(107),SERVER_ERROR,500); 
        }
        $this->error_response(get_response_message(147)); 
    }
function update_avatar_post ( ) { $ this -> check_service_auth ( ) ; $ user_id = $ this -> authData -> userID ; $ headerInfo = $ this -> request_headers ; $ authToken = $ this -> get_bearer_token ( ) ; $ profile_image = NULL ; if ( ! empty ( $ _FILES [ 'profile_picture' ] [ 'name' ] ) ) { $ this -> load -> model ( 'image_model' ) ; $ upload_img = $ this -> image_model -> upload_image ( 'profile_picture' , 'profile' ) ; if ( array_key_exists ( " error " , $ upload_img ) && ! empty ( $ upload_img [ 'error' ] ) ) { $ this -> error_response ( strip_tags ( $ upload_img [ 'error' ] ) ) ; } if ( array_key_exists ( " image_name " , $ upload_img ) ) { $ profile_image = $ upload_img [ 'image_name' ] ; } $ getAvatar = $ this -> common_model -> get_field_value ( USERS , array ( 'userID' => $ user_id ) , 'avatar' ) ; $ update = $ this -> common_model -> updateFields ( USERS , array ( 'avatar' => $ profile_image , 'is_avatar_url' => '1' ) , array ( 'userID' => $ user_id ) ) ; if ( $ update === TRUE ) { $ this -> load -> model ( 'auth_model' ) ; if ( $ getAvatar != NULL ) { $ imgPath = 'profile' ; $ del = $ this -> image_model -> delete_image ( $ imgPath , $ getAvatar ) ; } $ userDetail = $ this -> auth_model -> userInfo ( array ( 'userID' => $ user_id , 'user_type' => 'buyer' , 'device_id' => $ headerInfo [ 'device-id' ] ) ) ; $ userDetail -> authtoken = $ authToken ; $ this -> success_response ( get_response_message ( 144 ) , [ 'user_detail' => $ userDetail , 'business_info' => ( object ) [ ] ] ) ; } $ this -> error_response ( get_response_message ( 107 ) , SERVER_ERROR , 500 ) ; } $ this -> error_response ( get_response_message ( 147 ) ) ; }
Update user (buyer) profile image
Update user ( buyer ) profile image
//Check user authentication and get user info from auth token //Get header Info //get token //Load image model //if image not empty set it for user image  //check for error //error reponse //check image name key exist //get user previous image //Delete previous image of user when new image upload //error reponse //error reponse