Is it possible to override browser settings for specific file types using PHP headers?

When serving files from a PHP script, you can use PHP headers to control how the browser handles those files. To override browser settings for specific file types, you can use the "Content-Disposition" header with the "attachment" value to force the browser to download the file instead of displaying it. This is useful for file types that the browser may try to display, such as PDFs or images.

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