Solved

PHP Headers/Safari issue

Posted on 2009-03-30
4
2,659 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Several part series to implement Internet Explorer 11 Enterprise Mode
These days socially coordinated efforts have turned into a critical requirement for enterprises.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
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…

706 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

19 Experts available now in Live!

Get 1:1 Help Now