Get rid of the line break.
$path = 'uploads/' . $loggedInUser->username . '/' . $foldername;
If that doesn't work, you are likely having a permissions problem.
Also, your approach is completely insecure! Anyone can post ../
in their username and put a directory wherever they want in your file system.
Finally, when you specify a Location:
header, you must use a full URL. Most browsers will accept a relative resource like you have, but not all.