What are the potential pitfalls of using multiple "Content-Type" headers in PHP scripts for file downloads?
Using multiple "Content-Type" headers in PHP scripts for file downloads can lead to conflicts and unexpected behavior. To avoid this issue, it's important to set the correct "Content-Type" header for the specific file type being downloaded and ensure that only one "Content-Type" header is sent in the response.
<?php
// Set the correct Content-Type header based on the file type
$file = 'example.pdf';
$mime_type = mime_content_type($file);
header('Content-Type: ' . $mime_type);
// Output the file content
readfile($file);
?>