What is the recommended method for checking file types and preventing executable files from being uploaded in PHP forms?

To check file types and prevent executable files from being uploaded in PHP forms, you can use the `$_FILES` superglobal to access the file information and check the file type before allowing the upload to proceed. One common method is to use the `mime_content_type()` function to get the MIME type of the file and compare it against a list of allowed MIME types. Additionally, you can check the file extension to further validate the file type.

// Check if file is uploaded
if(isset($_FILES['file'])) {
    $file = $_FILES['file'];
    
    // Check file type using MIME type
    $allowedTypes = ['image/jpeg', 'image/png', 'image/gif'];
    $fileType = mime_content_type($file['tmp_name']);
    
    if(in_array($fileType, $allowedTypes)) {
        // Process file upload
        move_uploaded_file($file['tmp_name'], 'uploads/' . $file['name']);
        echo 'File uploaded successfully!';
    } else {
        echo 'Invalid file type. Please upload a valid image file.';
    }
}