Hard code to CSV problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jajumbo
Forum Newbie
Posts: 6
Joined: Wed Jul 26, 2006 4:32 pm

Hard code to CSV problem

Post by jajumbo »

Hey all, I have a problem with the following codes

Code: Select all

<?php
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=myamazingfile.csv");
header("Pragma: no-cache");
header("Expires: 0");

// Create the .CSV data
$data  = "csvtest1, csvtest2\n";
$data .= "\n";
$data .= "12,45\n";
$data .= "a,b\n";
$data .= "f4,4f\n";

//output the CSV 
echo $data;
?>
The above codes work in firefox, but it does not work in IE. However, that is supposed to work for everything.
This php file currently simply generates the CSV file when someone links to it.

Jajumbo
User avatar
hanji
Forum Commoner
Posts: 46
Joined: Fri Apr 29, 2005 3:23 pm

Post by hanji »

Not sure if this will help. I had trouble with zlib compression and IE, and came across this snip of code. It worked for me.

Code: Select all

if(isset($_SERVER['HTTP_USER_AGENT']) && preg_match("/MSIE/", $_SERVER['HTTP_USER_AGENT'])) {
     ini_set( 'zlib.output_compression','Off' );
}
I was doing force-download though.. so this might not apply to your problem.

hanji
jajumbo
Forum Newbie
Posts: 6
Joined: Wed Jul 26, 2006 4:32 pm

Post by jajumbo »

hanji wrote:Not sure if this will help. I had trouble with zlib compression and IE, and came across this snip of code. It worked for me.

Code: Select all

if(isset($_SERVER['HTTP_USER_AGENT']) && preg_match("/MSIE/", $_SERVER['HTTP_USER_AGENT'])) {
     ini_set( 'zlib.output_compression','Off' );
}
I was doing force-download though.. so this might not apply to your problem.

hanji
Thanks, but that didn't help.

the problem still remains for some strange reasons, IE would download my php file instead of the file name I told it to.

so I'd see would you like to open or save 'myphpname.php' ?? But of coz, like any standard php enbled servers, php files are not accessable to the www browser. hence ending up with an error message of unlocateable file myphpname.php


while in firefox, it see what I told it to save the file as, and it works.
User avatar
Mordred
DevNet Resident
Posts: 1579
Joined: Sun Sep 03, 2006 5:19 am
Location: Sofia, Bulgaria

Post by Mordred »

First link on google, is that it? :
http://support.microsoft.com/kb/q279667/
jajumbo
Forum Newbie
Posts: 6
Joined: Wed Jul 26, 2006 4:32 pm

Post by jajumbo »

Mordred wrote:First link on google, is that it? :
http://support.microsoft.com/kb/q279667/
Thanks,

But it is not the answer.

The problem I am having is that the code is generated on the fly, because it will be linked to a database,
And since the site would be widely accessed, it would be impossible to save the contents to a local file and then have it send over since many users could be requesting at the same time which would then cause a problem.

So the codes as shown in the orignal post was to create a CSV on the fly with instant data.

This would work in Firefox, but it failed miserably in IE 6.
jajumbo
Forum Newbie
Posts: 6
Joined: Wed Jul 26, 2006 4:32 pm

Post by jajumbo »

I think I might have solved the problem.


I am not sure if anyone will run into this problem again in the future, but here is the possible scenario.

Since I am using IIS, the php file is somehow not being executed but just simply transfered over to the browser.

This would not happend in Apache which would simply execute the file and return what ever that is being sent to it.

Solutions lies in turning a specific flag on in IIS, but since I am more of a linux person, I don't know which flag that really is.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Has IIS been configured to parse PHP - i.e. do other PHP scripts work?

Mac
Post Reply