Solved

PHP Headers/Safari issue

Posted on 2009-03-30
4
2,673 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
  • 2
  • 2
4 Comments
 
LVL 39

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 39

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

I had to do a bit of research to find the answer to this question so I thought I'd share my results.  Due to our outdated mainframe systems, we need to downgrade IE9 to IE8 in order to stay compatible.  We also needed to downgrade Java.  In order to…
Do you come here a lot? Are you lazy like me and don't want to go through the "trouble" of having to click your Dock's Safari icon and then having to click your Experts Exchange Favorites bookmark to get here? Well then this article is for you.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Shows how to create a shortcut to site-search Experts Exchange using Google in the Chrome browser. This eliminates the need to type out site:experts-exchange.com whenever you want to search the site. Launch the Search Engine Menu: In chrome, via you…

932 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now