downloading a csv file
im having a problem when downloading a csv file using php, ideally i want to visit a page and it just prom,pts me to save the file-
i have tried this here开发者_JAVA技巧-
$filename = 'dump.csv';
header("Content-type: text/csv");
header("Content-Disposition: attachment; filename=\"".$filename."\"");
and it has been returning a empty file, even though when i do-
echo filesize($filename);
it returns 19000 ?
You have to read the content of the file in and then output it.
Otherwise you are just sending the headers telling the browser to expect the file.
You would need to echo out the contents of the file. For example, after your header functions you would have something like:
$fh = fopen($filename, "r");
while($line = fgets($fh)){
echo $line;
}
fclose($fh);
精彩评论