What is the purpose of setting the Content-Disposition header in PHP?
Setting the Content-Disposition header in PHP allows you to control how the browser should handle the response from the server. This header is commonly used to force a file download instead of displaying the content in the browser window. By specifying the attachment value in the Content-Disposition header, you can prompt the browser to download the file as an attachment.
<?php
$file = 'example.pdf';
header('Content-Type: application/pdf');
header('Content-Disposition: attachment; filename="' . basename($file) . '"');
readfile($file);
exit;
?>