Here is how I did it.
header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename=file.csv')); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); echo "\xEF\xBB\xBF"; // UTF-8 BOM echo $csv_file_content; exit();
Of course, you can replace echo $csv_file_content with what you need.
source share