...

View Full Version : Forcing Browser to download a txt file



Immulsifier
11-21-2007, 07:09 PM
Hi

This is something im really struggling with. I have a txt file called text.txt on my server which I am wanting to force the browser to download. No matter what I try it just displays the contents of the file.

Can anyone help.
Phil

Fumigator
11-21-2007, 07:33 PM
Look at example #1595 on this page of the PHP manual (the header() function):

http://us2.php.net/header

matak
11-21-2007, 08:38 PM
you can use .htaccess if you don't want php solution.

Immulsifier
11-22-2007, 12:24 AM
Thanks for the help, I got it working in the end with some help from the comments on the php pages. Some of those comments are more useful than the php functions manual to be honest :)

JustBlaze
11-22-2007, 08:34 AM
Thanks for the help, I got it working in the end with some help from the comments on the php pages. Some of those comments are more useful than the php functions manual to be honest :)

Could you post the solution, as I'm curious how to do this.
-Thanks
JustBlaze

Immulsifier
11-22-2007, 05:00 PM
Sure



$filename = "text.txt";
$filepath = "./".$filename;

header("Cache-control: private");
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Length: ' . filesize($filepath));
header('Content-Disposition: attachment; filename=' . $filename);
readfile($filename);



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum