How can PHP be used to upload and rename files on a website?

To upload and rename files on a website using PHP, you can use the move_uploaded_file() function to move the uploaded file to a new location with a new name. You can also use the $_FILES superglobal array to access information about the uploaded file, such as its name and temporary location.

<?php
$uploadedFile = $_FILES['file']['tmp_name'];
$fileName = $_FILES['file']['name'];
$newFileName = 'new_file_name.txt';

if(move_uploaded_file($uploadedFile, 'uploads/' . $newFileName)){
    echo "File uploaded and renamed successfully.";
} else{
    echo "Error uploading file.";
}
?>