What are the potential implications of not setting the appropriate headers when prompting a file download in PHP?

If the appropriate headers are not set when prompting a file download in PHP, the file may not be downloaded correctly or the browser may try to display the file instead of downloading it. This can lead to unexpected behavior and potential security risks. To solve this issue, you need to set the necessary headers such as Content-Type and Content-Disposition to ensure the file is downloaded correctly.

<?php
$file = 'example.pdf';
header('Content-Type: application/pdf');
header('Content-Disposition: attachment; filename="' . basename($file) . '"');
readfile($file);
exit;
?>