0

I'm already adding the Content-Type: text/csv header but Safari is still adding the .html extension. No other tested browsers behave this same way, all others download correctly.

File name is example.csv but when downloaded through safari is saved as example.csv.html

$data = "1,bob,programmer\n";
$data .= "2,steve,manager\n";
$data .= "3,jim,ceo\n";
header('Content-Type: text/csv');
header('Content-Disposition: attachment; filename=export.csv');
header("Pragma: no-cache");
header("Expires: 0");
echo $data;
exit();

How can I prevent safari from adding on the html extension?

Edit: Even with the changes suggested below, I continue to get 'export.csv.html' on download in safari

Cryptic
  • 406
  • 1
  • 4
  • 13
  • You are going to need to show your code. – rjdown Aug 12 '15 at 23:27
  • Essentially a duplicate of this: [Safari adding .html to download](http://stackoverflow.com/questions/19363744/safari-adding-html-to-download). Check out the responses in there. – Erik Johansson Aug 12 '15 at 23:36
  • @ErikJohansson Unfortunately, that thread is about xls and a file generated to disk, I'll provide some clarity on my question and provide some code. – Cryptic Aug 12 '15 at 23:43
  • possible duplicate of [Create a CSV File for a user in PHP](http://stackoverflow.com/questions/217424/create-a-csv-file-for-a-user-in-php) – RiggsFolly Aug 13 '15 at 00:12
  • Try `filename="export.csv"'` without the double quotes i.e. `filename=export.csv'` – RiggsFolly Aug 13 '15 at 00:14
  • @RiggsFolly That other SO question is similar, but I don't see any specific of safari. FWIW, other downloads (using the same 'download' function which adds the headers and echos the content) work correctly in safari. – Cryptic Aug 13 '15 at 00:55

0 Answers0