What are the alternatives to using "force-download" in PHP for better compatibility with different browsers?

When using the "force-download" method in PHP to prompt a file download, it may not work correctly on all browsers. To ensure better compatibility, you can use the Content-Disposition header with the "attachment" value to instruct the browser to download the file as an attachment.

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