Page 1 of 1
Hard code to CSV problem
Posted: Mon Oct 02, 2006 2:27 pm
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
Posted: Mon Oct 02, 2006 2:35 pm
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
Posted: Mon Oct 02, 2006 3:31 pm
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.
Posted: Mon Oct 02, 2006 4:47 pm
by Mordred
Posted: Wed Oct 04, 2006 8:15 am
by jajumbo
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.
Posted: Wed Oct 04, 2006 9:28 am
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.
Posted: Wed Oct 04, 2006 10:19 am
by twigletmac
Has IIS been configured to parse PHP - i.e. do other PHP scripts work?
Mac