How can the use of Content-disposition header affect file downloads in different browsers?
The Content-disposition header can affect file downloads in different browsers by specifying whether a file should be displayed inline or downloaded as an attachment. To ensure consistent behavior across browsers, it is recommended to set the Content-disposition header to "attachment". This will prompt the browser to download the file instead of trying to display it inline.
<?php
$file = 'example.pdf';
header('Content-Description: File Transfer');
header('Content-Type: application/pdf');
header('Content-Disposition: attachment; filename="'.basename($file).'"');
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
readfile($file);
exit;
?>