How important is it to follow RFC guidelines when setting up file downloads in PHP?
It is crucial to follow RFC guidelines when setting up file downloads in PHP to ensure compatibility with various browsers and prevent security vulnerabilities. One common guideline is to set the correct MIME type for the file being downloaded. This can be done using the header() function in PHP.
$file = 'example.pdf';
header('Content-Type: application/pdf');
header('Content-Disposition: attachment; filename="' . basename($file) . '"');
readfile($file);
exit;