Solved

PHP Headers/Safari issue

Posted on 2009-03-30
4
2,792 Views
Last Modified: 2013-12-07
Experts,
 I have a PHP script which outputs a csv which I am then trying to force as a download through the browser.

This works in IE and Firefox, however in Safari I am having some problems.

I have tried any number of header content-types, however the best I can end up with is Safari either appending .txt or .exe to the filename.

I have tried:

header("Content-type: application/octet-stream");
header("Content-type: application/csv");
header("Content-type: application/x-msdownload");
header("Content-type: text/x-csv");
header("Content-type: text/csv");
header("Content-type: csv");


With the following:

header("Content-Disposition: attachment; filename=\"".$filename.".csv\"");

Can anyone help? I simply want Safari to download xxx.csv!

Many thanks
0
Comment
Question by:0tacon
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 40

Expert Comment

by:Eoin OSullivan
ID: 24017449
I've used the following code to save as XLS and it works in Safari ... try replacing the CSV in the filename and leave out all your other Content-type header values.


header("Content-type: application/octet-stream");
$theFile=$filename.".xls";
header("Content-Disposition: attachment; filename=".$theFile);
header("Pragma: no-cache");
header("Expires: 0");

Open in new window

0
 
LVL 12

Author Comment

by:0tacon
ID: 24017644
Safari is still outputting with a .txt extension (so the file is downloaded as xxxxx.xls.txt)

Thanks for looking into this :)
0
 
LVL 40

Accepted Solution

by:
Eoin OSullivan earned 250 total points
ID: 24017735
Did you try it with a CSV extension??

My Safari 3.2 works fine with the code above.

I am wondering if you have MS Office installed on your Mac?

Safari handles file extensions a little differently from Firefox as it relies on the Extensions being setup in OSX.  If not it "guesses" the filetype and appends "txt" etc. to filenames

It is explained better in this article
http://groups.google.com/group/microsoft.public.mac.office.word/browse_thread/thread/00a400dd0214abed?pli=1

Apple are aware of the issue
http://support.apple.com/kb/TA24293?viewlocale=en_US

Basically you need to assign the CSV file type to an application like Excel or numbers on your Mac.


I use this FREE system preference to manage all my file extensions
http://creativetechs.com/tipsblog/set-default-applications-in-mac-os-x/
0
 
LVL 12

Author Comment

by:0tacon
ID: 24017767
Thanks for the depth of the answer, I had a feeling this was the case- With file associations set up it works fine.

Cheers again
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Google currently has a new report that is in beta and coming soon to Webmaster Tool accounts. This Micro Tutorial will highlight new features for Google Webmaster Tools.

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question