Try this block of code
$imagename = $_FILES['profilepic']['name'];
$source = $_FILES['profilepic']['tmp_name'];
$imagename = str_replace(" ", "_", $imagename);
$target = "userdata/".$_POST['username']."/profilepic" . $imagename;
move_uploaded_file($source, $target);
Make sure you have got write permission to the folder userdata,plmexico,profilepic.
Good habits:
Rename the user's file with a name generated by your algorithm. As you want to replace the profile pic when they upload a new picture you naming can combine user_id with the file name. So the code becomes.
$localname = $_FILES['profilepic']['name'];
$imagename = $user_id."_profile".explode(end(",",$localname)); // $user_id is the user's id
$source = $_FILES['profilepic']['tmp_name'];
$imagename = str_replace(" ", "_", $imagename);
$target = "userdata/".$_POST['username']."/profilepic" . $imagename;
move_uploaded_file($source, $target);
This code doesn't work if the user uploads an image in different format.
@and see what you get.