The dirname function returns a parent directory's path

    
    $filename = 'user/smith1022/path/to/foo.txt';

    $dirname =  dirname($filename);

    echo $dirname;
    // user/smith1022/path/to