Skip to content

Instantly share code, notes, and snippets.

@ternavsky
Last active August 29, 2015 14:22
Show Gist options
  • Save ternavsky/ea9787a12b44765f99cf to your computer and use it in GitHub Desktop.
Save ternavsky/ea9787a12b44765f99cf to your computer and use it in GitHub Desktop.
Force download CSV file
function forceCSVFileDownload($filename, $csv) {
header('Content-Disposition: attachment; filename="'.$filename.'"');
header('Content-Type: csv/plain'); # Don't use application/force-download - it's not a real MIME type, and the Content-Disposition header is sufficient
header('Content-Length: ' . strlen($csv));
header('Connection: close');
print($csv);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment