Jquery PHP criando pasta duplicada

Estou usando Jquery, PHP e MySql seguindo um curso Udemy, já revisei o código e não consigo achar pq está criando 2 pastas profilePhoto:
! - user/14/profilePhoto (esta apenas que deveria ser criada e salvar as imagens aqui, este 14 é o Id do usuário)

2 - user/profilePhoto ( ela cria esta outra e tenho que mover manualmente para a primeira para poder mostrar a foto no site)

profilePhoto

O que fiz de errado para criar a pasta 2 e salvar as imagens nesta pasta errada?

javascript Ajax

 $(document).on('change', '#profile-upload', function(){
            var name = $('#profile-upload').val().split('\\').pop();
            var file_data = $('#profile-upload').prop('files')[0];
            var file_size = file_data["size"];
            var file_type = file_data["type"].split('/').pop();
            var userid =  '<?php echo $userid; ?>';
            var imgName = 'user/' + userid + '/profilePhoto/' + name + '';
            var form_data = new FormData();
            form_data.append('file', file_data);
            if(name != ''){
                $.post('http://localhost/facebook/core/ajax/profilePhoto.php', 
                {imgName: imgName, userid: userid}, function(data){
                    
                })

                $.ajax({
                url: 'http://localhost/facebook/core/ajax/profilePhoto.php',
                cache: false,
                contentType: false,
                processData: false,
                data: form_data,
                type: 'post',                
                success: function(data){
                   
                    $('.profile-pic-me').attr('src', ""+data+"");
                    $('.profile-dialog-show').hide();
                }
                })


            }

        })

profilePhoto,php

include '../load.php';
include '../../connect/login.php';

$userid = Login::isLoggedIn();

if(isset($_POST['imgName'])){
    $imgName = $loadFromUser->checkInput($_POST['imgName']);
    $userid = $loadFromUser->checkInput($_POST['userid']);

    $loadFromUser->update('profile', $userid, array('profilePic' => $imgName));    
}

if ( 0 < $_FILES['file']['error'] ) {
    echo 'Error: ' . $_FILES['file']['error'] . '<br>';
}
else {
    $path_directory = $_SERVER['DOCUMENT_ROOT']."/facebook/user/".$userid. "/profilePhoto/"; 
    if(!file_exists($path_directory) && !is_dir($path_directory)){
        mkdir($path_directory, 0777, true);
    }

    move_uploaded_file($_FILES['file']['tmp_name'], $path_directory.$_FILES['file']['name']);

    echo 'user/'.$userid.'/profilePhoto/'.$_FILES['file']['name'];
    // echo $path_directory.$_FILES['file']['name'];

    
}

O banco gerado:

quando coloco direto o 14 que equivlente ao ID funciona perfeito

$path_directory = $_SERVER['DOCUMENT_ROOT']."/facebook/user/14/profilePhoto/"; if(!file_exists($path_directory) && !is_dir($path_directory)){ mkdir($path_directory, 0777, true); }

$path_directory = $_SERVER['DOCUMENT_ROOT']."/facebook/user/".$userid."/profilePhoto/"; if(!file_exists($path_directory) && !is_dir($path_directory)){ mkdir($path_directory, 0777, true); }

ou

$path_directory = $_SERVER['DOCUMENT_ROOT']."/facebook/user/{$userid}/profilePhoto/"; if(!file_exists($path_directory) && !is_dir($path_directory)){ mkdir($path_directory, 0777, true); }

usando o $userid dá problema