What is the correct way to set the Content-Type header for downloading CSV files in PHP?

When downloading CSV files in PHP, it is important to set the Content-Type header to "text/csv" to ensure that the browser interprets the file correctly. This header informs the browser that the content being sent is in CSV format, allowing it to display or download the file appropriately.

<?php
$file = 'example.csv';

header('Content-Type: text/csv');
header('Content-Disposition: attachment; filename="' . $file . '"');

readfile($file);
exit;
?>