Forum Moderators: coopster

Message Too Old, No Replies

header("Content-Type: plain/text");

         

yllai

4:14 am on May 17, 2006 (gmt 0)

10+ Year Member



Following is my script. When I run this script, I want to generate a txt file with some words "This is sample" for user download. But, after I download the file, the content is all the script but not plain text words "This is sample". Any mistake with my script? Anyone can correct it for me?

<?php
$filecontent="This is sample";
$downloadfile="test.txt";

header("Content-Type: plain/text");
header("Content-disposition: attachment; filename=$downloadfile");
header("Content-Transfer-Encoding: binary");
header("Pragma: no-cache");
header("Expires: 0");

echo"$filecontent";

?>

Thanks in advanced.

siMKin

9:43 am on May 17, 2006 (gmt 0)

10+ Year Member



there's nothing wrong with your script. this should give the user the option to save a text file and this text file should contain only the words 'This is sample'
(and in fact, it does. i just tested it)

yllai

10:19 am on May 17, 2006 (gmt 0)

10+ Year Member



I get blank txt file with this script. Is it my IE not support this script? (IE 6.0)

dreamcatcher

10:41 am on May 17, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try using readfile after the headers instead of echo:

readfile($downloadfile);

dc

siMKin

10:42 am on May 17, 2006 (gmt 0)

10+ Year Member



it shouldn't matter what browser you're using.

[edited by: coopster at 2:11 pm (utc) on May 17, 2006]
[edit reason] removed url per TOS [webmasterworld.com] [/edit]

yllai

11:11 am on May 17, 2006 (gmt 0)

10+ Year Member



i still cannot get it...any other problem? my webserver is windowns server..can be?

coopster

2:14 pm on May 17, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Although modern browsers can be very forgiving perhaps your version is not. You have the MIME type reversed:
header("Content-Type: text/plain");

That is likely not the error though. Do you see your full source when you "View Source" in your browser? If so, then you are not parsing your PHP. Check the filename extension of the script and your server configuration.