How can PHP developers differentiate between progressive and non-progressive JPEG files during file uploads to address compatibility issues with certain programs or platforms?

Progressive JPEG files display an image gradually as it loads, while non-progressive JPEG files load the image in one go. To differentiate between the two during file uploads in PHP, developers can check the JPEG headers for specific markers that indicate progressive encoding. By identifying the encoding type, developers can address compatibility issues with programs or platforms that may not support progressive JPEGs.

// Check if the uploaded file is a progressive JPEG
function isProgressiveJPEG($file) {
    $fp = fopen($file, 'rb');
    fseek($fp, 0);
    $data = fread($fp, 2);
    fclose($fp);
    
    // Check for the progressive JPEG marker
    if (bin2hex($data) == 'ffd8ffdb') {
        return true;
    }
    
    return false;
}

// Example usage
$uploadedFile = 'path/to/uploaded/file.jpg';
if (isProgressiveJPEG($uploadedFile)) {
    echo 'Progressive JPEG detected';
} else {
    echo 'Non-progressive JPEG detected';
}