How can the MIME type and file extension be manipulated in PHP to prompt the browser to recognize a file as downloadable, and what considerations should be taken into account when doing so?

To prompt the browser to recognize a file as downloadable in PHP, you can set the MIME type and file extension headers. This can be done using the header() function in PHP. It is important to ensure that the MIME type matches the actual content of the file to prevent any security risks.

$file = 'example.pdf';
$filename = 'downloaded_file.pdf';

header('Content-Type: application/pdf');
header('Content-Disposition: attachment; filename="' . $filename . '"');
readfile($file);