Page 1 of 1

[SOLVED]File download doesn't work in Google Chrome

Posted: Fri Aug 06, 2010 2:53 am
by barb woolums
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.

Code: Select all

                                                                 $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');

Re: File download doesn't work in Google Chrome

Posted: Fri Aug 06, 2010 10:51 am
by pickle
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.