views:

1034

answers:

4

I have a interesting problem that I think is server related. I want CSV data to be saved as a CSV file when a user clicks a button. It works fine on my development server, but on the production it just echo's the content to the page. My guess is that it must be a server issue, but I'm really not sure what it could be. Can GZIP affect this?

My header code is as follows:

header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Length: " . strlen($out));
header("Content-type: text/x-csv");
header("Content-Disposition: attachment; filename=$filename");
echo $out;

So this code above works on a development server and on the production will just echo the CSV to the page. Any ideas?

A: 

The only thing that I can think of is the mime-type. I've had some problems with mime-types (especially with .flv files) when moving from one server to another.

What I've used for .csv files is application/octet-stream.

Hope that helps

Matti
I tried application/octet-stream with the same problem... thanks though
AndreLiem
A: 

Yeah I'd guess it's the mime-type as well. You may want to try the csv specific "text/csv" (RFC 4180) or the generic "application/octet-stream".

cOle2
A: 

Just use Wireshark (http://www.wireshark.org) and capture the HTTP-traffic for both cases and look for differences. Fiddler is also supposed to work

Christian
Thanks for the tip, I tried out fiddler and interestingly enough the header on the live server is set to:text/html; charset=iso-8859-1and nottext/x-csvI'm not sure why it would be overriden though... really strange.
AndreLiem
A: 

Did you resolve this? I am having the same problem - with the header being set to text/html on the live server despite the fact that the code is supposed to be setting it to text/csv.

maxxyb
actually, I had a common php bug that was causing this and it had nothing to do with the header type. Basically, I had a configuration php file that was being included, it was echoing a warning before the CSV was being outputted... so unfortunately not related. If you set the header and content types that should work?
AndreLiem