Page 1 of 1

present file to user in header

Posted: Mon May 16, 2005 3:37 pm
by bluesman333
Can anyone tell me what is wrong here?

I want to create a .txt file and then give the user the option of opening it in excel or saving it somewhere.

Here is the code:

Code: Select all

$temp = tmpfile();
fwrite($temp, $out);//$out is a string containing the file output
	

header("Content-type: application/msexcel"); 
header("Content-Disposition: attachment; filename=".$eventname.".txt");
readfile($temp);
What I'm getting is a file with the html output.

Posted: Mon May 16, 2005 3:49 pm
by hawleyjr
That is because your browser is trying to read a text file. save the file as a CSV file.

Posted: Mon May 16, 2005 4:02 pm
by bluesman333
that didn't seem to help.

same result

Re: present file to user in header

Posted: Mon May 16, 2005 4:24 pm
by Roja
bluesman333 wrote:Can anyone tell me what is wrong here?

Code: Select all

$temp = tmpfile();
[b]header("Content-type: application/msexcel"); [/b]
header("Content-Disposition: attachment; filename=".$eventname.".txt");
readfile($temp);
What I'm getting is a file with the html output.
You meant to say..

Code: Select all

// Dont forget the dash!
header(&quote;Content-type: application/ms-excel&quote;);

header(&quote;Content-Disposition: attachment; filename=&quote;.$eventname.&quote;.xls&quote;);
Note the missing - in ms-excel, and the correct filename extension.

Posted: Mon May 16, 2005 4:54 pm
by bluesman333
that doesn't work either.

Posted: Mon May 16, 2005 5:32 pm
by pickle
Looking at your code, you're writing $out to the file, then sending the contents of that file. My guess is the contents of $out need to be adjusted if you're not getting what you want.