How can users customize the file type validation in an upload script to allow for specific formats?

When creating an upload script, users can customize the file type validation by checking the file's MIME type or extension to allow for specific formats. This can be done by defining an array of allowed file types and comparing the uploaded file's type against this list. If the file type matches one of the allowed types, the script can proceed with the upload process; otherwise, an error message can be displayed to the user.

<?php
$allowedFileTypes = array('image/jpeg', 'image/png', 'application/pdf');

if (isset($_FILES['file'])) {
    $fileType = $_FILES['file']['type'];
    
    if (in_array($fileType, $allowedFileTypes)) {
        // Proceed with the upload process
    } else {
        echo 'Invalid file type. Allowed file types are: ' . implode(', ', $allowedFileTypes);
    }
}
?>