How can I retain the original file name during an upload process in PHP?

When uploading files in PHP, the original file name can be retained by accessing the "name" property of the uploaded file in the $_FILES superglobal array. This property contains the original name of the file before it was uploaded to the server. By using this property, you can store the original file name in a variable and then use it to save the file with the same name on the server.

<?php
if ($_FILES['file']['error'] === UPLOAD_ERR_OK) {
    $originalFileName = $_FILES['file']['name'];
    $uploadPath = 'uploads/' . $originalFileName;
    
    if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadPath)) {
        echo "File uploaded successfully as $originalFileName.";
    } else {
        echo "Error uploading file.";
    }
} else {
    echo "Error uploading file: " . $_FILES['file']['error'];
}
?>