无法将上传的文件移动到php中的目录?

i am currently having a problem moving my uploaded file in php to directory, here is my php code:

<?php
  //Profile Image upload script
  if (isset($_FILES['profilepic'])) {
   if (((@$_FILES["profilepic"]["type"]=="image/jpeg") || (@$_FILES["profilepic"]["type"]=="image/png") || (@$_FILES["profilepic"]["type"]=="image/gif"))&&(@$_FILES["profilepic"]["size"] < 1048576)) //1 Megabyte
  {
   $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
   $rand_dir_name = substr(str_shuffle($chars), 0, 15);
   $dir = __DIR__."/userdata/profile_pics/$rand_dir_name";
   mkdir($dir);
   move_uploaded_file($_FILES["profilepic"]["tmp_name"],_DIR_."/userdata/profile_pics/$rand_dir_name".$_FILES["profile‌​pic"]["name"]);
    $profile_pic_name = $_FILES["profilepic"]["name"];
    $profile_pic_query = mysqli_query($conn,"UPDATE users2 SET profile_pic='$rand_dir_name/$profile_pic_name' WHERE username='$user'");

  }
  else
  {
      $msg5 =  "Invailid File! Your image must be no larger than 1MB and it must be either a .jpg, .jpeg, .png or .gif";
  }
  }

?>

The move_uploaded_file function doesn't seem to work here, i am able to make random directory, here is $user is the username of the user logged in.