If you would like to force a file download prompt to the user, instead of just outputting the text to the browser, use the following headers.
<?php
$filename = "some-filename";
header("Content-type: text/csv");
header("Content-Disposition: attachment; filename={$filename}.csv");
header("Pragma: no-cache");
header("Expires: 0");
The key here is setting the Content-Disposition
to attachment
. You can also tell the browser not to cache and provide a filename as well.
Just finishing up brewing up some fresh ground comments...