title: How do I rename a filename after uploading with php?
body: <p>How do I rename the file either before or after it gets uploaded? I just want to rename the filename, not the extension.</p>
  
  <pre><code>$changeTXT = $_SESSION['username'];
  $uploaderName = strtolower($changeTXT);
  $changeTXT = strtolower($changeTXT);
  $changeTXT = ucfirst($changeTXT);
  $filelocation = $_POST['userfile'];
  $filename = $_POST['filename'];
  $max_size = $_POST['MAX_FILE_SIZE'];
  
  $file = $_FILES['userfile'];
  
  $allowedExtensions = array("wma", "mp3", "wav");
  
  function isAllowedExtension($fileName) {
    global $allowedExtensions;
  
    return in_array(end(explode(".", $fileName)), $allowedExtensions);
  }
  
  if($file['error'] == UPLOAD_ERR_OK) {
    if(isAllowedExtension($file['name'])) {
  
  $uploaddir = "uploads/".$uploaderName."/";
  
  $uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
  
  if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
  
      echo "Thank you for uploading your music!&lt;br /&gt;&lt;br /&gt;";
  
  } else {
  
      echo "Your file did not upload.&lt;br /&gt;&lt;br /&gt;";
  
  }
  
      echo "\n";
  
      echo "&lt;a href='index.php'&gt;Return&lt;/a&gt; to index.&lt;br /&gt;&lt;br /&gt;$uploaddir";
  
  } else {
  
      echo "You have tried to upload an invalid file type.&lt;br /&gt;&lt;br /&gt;";
  
    }
  
  } else die("Cannot upload");
  </code></pre>