Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

PHP Headers/Safari issue

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
This Micro Tutorial will demonstrate how to add subdomains to your content reports. This can be very importing in having a site with multiple subdomains.
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…

719 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