What is the purpose of the Content-Disposition header in the PHP code for file download?
The Content-Disposition header in PHP code for file download is used to specify the presentation and file name of the downloaded file. This header allows the server to suggest a filename to the client when the file is downloaded, making it easier for the user to identify and save the file correctly.
<?php
$file = 'example.pdf';
header('Content-Description: File Transfer');
header('Content-Type: application/pdf');
header('Content-Disposition: attachment; filename="' . basename($file) . '"');
readfile($file);
exit;
?>
Keywords
Related Questions
- What are the benefits of including necessary files in PHP for website development?
- What are the key considerations when trying to link user accounts between a website and a PHPBB forum to avoid duplication or data corruption?
- What is the correct method to remove a specific entry from a session array in PHP?