Here\'s what I\'m trying to do. I have a series of reports that they also want to be able to download as comma delimited text files. I\'ve read over a bunch of pages where
I overlooked the way you are writing out the contents before asking you to try closing the file.
Check the fwrite manual here: http://php.net/manual/en/function.fwrite.php
What you need to do is:
$filename = "yourfile.txt";
#...
$f = fopen($filename, 'w');
fwrite($f, $content);
fclose($f);
and after closing the file, you can now safely send it across for download.
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Length: ". filesize("$filename").";");
header("Content-Disposition: attachment; filename=$filename");
header("Content-Type: application/octet-stream; ");
header("Content-Transfer-Encoding: binary");
readfile($filename);
There are a couple of things:
application/octet-stream
. Why not set a more real type as text/plain
?readfile(..)