In what situations should HTML tags be removed from a PHP script that handles file downloads?
HTML tags should be removed from a PHP script that handles file downloads when the script is meant to output binary data (such as images, PDFs, etc.) to the browser. Including HTML tags in such a script can corrupt the binary data and prevent the file from being downloaded or displayed correctly. To ensure proper handling of binary data, all HTML tags should be removed from the PHP script that handles file downloads.
<?php
// Set headers for file download
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="example.pdf"');
// Output the binary data
readfile('path/to/example.pdf');
exit;
?>