How can the Content-Disposition header be effectively utilized in PHP to prompt file downloads with the correct filename and prevent file corruption during download?

When serving files for download in PHP, it is important to set the Content-Disposition header with the filename to ensure that the browser prompts the user to download the file with the correct name. This can prevent file corruption during download by specifying the file's original name.

<?php
$file_path = 'path/to/your/file.pdf';
$file_name = 'downloaded_file.pdf';

header('Content-Description: File Transfer');
header('Content-Type: application/pdf');
header('Content-Disposition: attachment; filename="' . $file_name . '"');
header('Content-Length: ' . filesize($file_path));

readfile($file_path);
exit;
?>