text file download on .php page

text file download on .php page

am 01.01.2008 14:07:51 von r_ahimsa_m

Hello,
I am learning PHP5. I have little experience.
I have created a website in which I want to put a link to download a text
file. When I used simple

I had such problem that instead of dowloading the file contents was
displayed in browser. In some book on PHP5 I found a "solution": create a
link

and prepare Download.php file:

if (isset($_GET['dir']) && isset($_GET['file']))
{
$file = $_GET['dir'] . '/' . $_GET['file'];
$fd = fopen($file, 'r');
$size = filesize($file);
$contents = fread($fd, $size);
fclose($fd);
header("Content-Type: application/octet-stream");
header("Content-Length: $size;");
header("Content-Disposition: attachement; filename=$file");
echo $contents;
}
?>

But... again the file contents is displayed instead of downloading.
Could you help me please to write it correctly?
Thank you!
/RAM/

Re: text file download on .php page

am 01.01.2008 15:39:15 von Jerry Stuckle

R.A.M. wrote:
> Hello,
> I am learning PHP5. I have little experience.
> I have created a website in which I want to put a link to download a text
> file. When I used simple
>
> I had such problem that instead of dowloading the file contents was
> displayed in browser. In some book on PHP5 I found a "solution": create a
> link
>
> and prepare Download.php file:
>
> > if (isset($_GET['dir']) && isset($_GET['file']))
> {
> $file = $_GET['dir'] . '/' . $_GET['file'];
> $fd = fopen($file, 'r');
> $size = filesize($file);
> $contents = fread($fd, $size);
> fclose($fd);
> header("Content-Type: application/octet-stream");
> header("Content-Length: $size;");
> header("Content-Disposition: attachement; filename=$file");
> echo $contents;
> }
> ?>
>
> But... again the file contents is displayed instead of downloading.
> Could you help me please to write it correctly?
> Thank you!
> /RAM/
>
>
>

Nothing is wrong with the code.

This is completely up to the browser. You can make recommendations, but
that's all.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================