What best practices should be followed when setting headers for file downloads in PHP to ensure compatibility with different browsers?

When setting headers for file downloads in PHP, it is important to ensure compatibility with different browsers by setting the correct content type and attachment disposition. This involves setting the "Content-Type" header to the appropriate MIME type of the file being downloaded and the "Content-Disposition" header to "attachment; filename=filename.extension".

<?php
$file = 'example.pdf';
header('Content-Type: application/pdf');
header('Content-Disposition: attachment; filename="' . basename($file) . '"');
readfile($file);
exit;
?>