How can the issue of kryptisch content in downloaded DOC files be resolved when using PHP's readfile function?

Issue: When using PHP's readfile function to download DOC files, the content may appear kryptisch due to encoding issues. To resolve this, we can set the appropriate content type and headers before outputting the file.

<?php
$file = 'example.doc';

header('Content-Description: File Transfer');
header('Content-Type: application/msword');
header('Content-Disposition: attachment; filename="'.basename($file).'"');
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));

readfile($file);
exit;
?>