What are the potential drawbacks of relying on file extensions for file validation in PHP?

Relying solely on file extensions for file validation in PHP can be risky as file extensions can be easily manipulated or spoofed. To improve file validation, it's recommended to use file mime types in addition to file extensions. This provides a more reliable way to verify the type of file being uploaded.

// Example of using file mime types for file validation in PHP
$allowedMimeTypes = ['image/jpeg', 'image/png', 'image/gif'];

if (in_array($_FILES['file']['type'], $allowedMimeTypes)) {
    // File is of an allowed type
    // Process file upload
} else {
    // File is not of an allowed type
    // Handle error accordingly
}