PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I am using the following code to download a file from a my server to my pc. It works on other browsers but no save dialog comes up on google chrome. Just wondering if anyone else has experienced this and has found a solution.
$fp = fopen("exported-recipes.csv", "a");
fwrite( $fp, $csv_output);
fclose($fp);
$size_file=filesize("exported-recipes.csv");
// We'll be outputting a csv file
header('Content-type: application/UTF-8');
// It will be called exported-recipes.csv
header('Content-Disposition: attachment; filename="exported-recipes.csv"');
//only output the contents of the file
header("Content-Description: Download PHP");
header("Content-Length: $size_file");
// The CSV source is in exported-recipes.csv
readfile('exported-recipes.csv');
Last edited by barb woolums on Sat Nov 20, 2010 11:56 am, edited 1 time in total.
It may be your Content-Type header. I've never seen "application/UTF-8" used. Usually for CSVs I use "text/csv". Since you're forcing a download, the type doesn't really matter a whole lot - but Chrome might be choking on it.
It's also slightly possible that Chrome isn't asking you to download, but is downloading it automatically for you. I know I encounter that behaviour sometimes in Safari - and Chrome shares the same engine.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.