What are the potential compatibility issues between different browsers when downloading files using PHP?

Potential compatibility issues between different browsers when downloading files using PHP can arise from differences in how browsers handle content types and headers. To ensure compatibility, it's essential to set the appropriate content type and headers when sending the file to the browser. This can be done using PHP's header() function to specify the content type and force the browser to download the file rather than displaying it.

<?php
// Set the content type and headers for downloading a file
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="example.txt"');

// Output the file contents
readfile('path/to/file/example.txt');