2

I have an Exp Eng template that generate a .csv format file using a channel tag. I also insert the headers of the file using php, as shown below (those are the fist lines of the template). In Firefox the file downloads with a simple click on a link to the template and everything seems fine.

<?php 
header("content-type: text/csv");
header("content-disposition: attachment; filename=filename.csv");
header("Pragma: no-cache");
header("Cache-Control: private");
header("Expires: 0");

It all seems to be working but Safari on the Mac will insist on downloading it with an .html extension as in 'filename.csv.html'. I've researched this on the Internet at many say it is just a peculiarity with Safari. But another person accessing the file says it happens no matter what browser they are using.

In Exp Eng I have the template settings as an "html" template. The other choices don't seem to work, like RSS/feed, and static would disable the channel tag. Any ideas on how to get around this problem?

Thanks, Bob.

1

Per this StackOverflow answer, try adding the following to your .htaccess file:

AddType application/octet-stream .csv

Also, try changing your Content-Type header code to:

header('Content-Type: application/csv');
3
  • I tried these suggestions out and made these changes and the csv files download in other browsers as files as intended. But Safari still adds the '.html' on the end of the file name, even with these changes. I'm inclined to believe this is an issue only with Safari. – Bob Foster Mar 18 '13 at 23:18
  • Is it possible it's a browser caching issue? What's the URL? I'll test it here. – Anna_MediaGirl Mar 19 '13 at 2:58
  • Just for kicks... try changing the name of the CSV file as a test. – Anna_MediaGirl Mar 19 '13 at 4:09
0

Depending on the data you want to export, you might be able to accomplish your goal with the AJW Export plugin. Could be worth looking at if you haven't already.

1
  • I did look at this already but it seems to only use an SQL query. I needed to format the data also and combine fields. – Bob Foster Mar 18 '13 at 22:16
0

try next header:

header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=filename.csv');
header('Content-Transfer-Encoding: binary');
header('Accept-Ranges: bytes');
header('Cache-control: no-cache, pre-check=0, post-check=0');
header('Cache-control: private');
header('Pragma: private');
header('Expires: 0');c

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.