What is the purpose of using the headers "Content-Type", "Content-Length", "Content-Disposition" and "Content-Description" in PHP for file downloads?

The purpose of using headers like "Content-Type", "Content-Length", "Content-Disposition", and "Content-Description" in PHP for file downloads is to provide important information about the file being downloaded. These headers help the browser understand how to handle the file, such as displaying it in the browser or prompting the user to download it. By setting these headers correctly, you can ensure a smooth and predictable file download experience for users.

<?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);
?>