How can PHP developers handle different image types like 'image/jpeg' and 'image/pjpeg' when uploading images?

When uploading images in PHP, developers can handle different image types like 'image/jpeg' and 'image/pjpeg' by checking the MIME type of the uploaded file. This can be done using the $_FILES superglobal array which contains information about the uploaded file, including its MIME type. By checking the MIME type of the uploaded file, developers can ensure that only allowed image types are accepted for upload.

// Check if the uploaded file is of allowed image types
$allowedTypes = ['image/jpeg', 'image/pjpeg'];
if (!in_array($_FILES['file']['type'], $allowedTypes)) {
    echo 'Invalid file type. Only JPEG images are allowed.';
    exit;
}

// Process the uploaded file
// Your code to handle the uploaded file goes here