How do I rename the file either before or after it gets uploaded? I just want to rename the filename, not the extension.
$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!<br /><br />";
} else {
echo "Your file did not upload.<br /><br />";
}
echo "\n";
echo "<a href='index.php'>Return</a> to index.<br /><br />$uploaddir";
} else {
echo "You have tried to upload an invalid file type.<br /><br />";
}
} else die("Cannot upload");