What are common issues with MIME types not being transferred during file uploads in PHP?

Common issues with MIME types not being transferred during file uploads in PHP can occur due to incorrect server configurations or limitations on the server-side. To solve this issue, you can explicitly set the MIME type of the uploaded file using PHP's finfo extension or by validating the file type based on its extension.

// Validate uploaded file MIME type using finfo extension
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$mime = finfo_file($finfo, $_FILES['file']['tmp_name']);
finfo_close($finfo);

if ($mime == 'image/jpeg' || $mime == 'image/png') {
    // File is an image, proceed with upload
} else {
    // Invalid file type, do not proceed with upload
}