Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

PHP Headers/Safari issue

Posted on 2009-03-30
4
Medium Priority
?
2,876 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 41

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 41

Accepted Solution

by:
Eoin OSullivan earned 1000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

885 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