How can MIME types affect file uploads in PHP, particularly when distinguishing between JPEG and PJEG formats?

When uploading files in PHP, MIME types play a crucial role in determining the type of file being uploaded. One common issue arises when distinguishing between JPEG and PJEG formats, as some systems may incorrectly identify PJEG files as JPEG. To solve this issue, you can check the MIME type of the uploaded file and handle PJEG files separately if needed.

// Get the MIME type of the uploaded file
$mime = $_FILES['file']['type'];

// Check if the MIME type is PJEG
if ($mime == 'image/pjpeg') {
    // Handle PJEG file upload
} else {
    // Handle JPEG file upload
}