Hey,
I want to 'force' the download of a plain text file in PHP.
I have the following code, which I picked up on the web somewhere:
if (isset($_REQUEST["file"])) {
$file=$_REQUEST["file"];
header("Content-type: application/force-download");
header("Content-Transfer-Encoding: ansi");
header("Content-length: ".filesize($file));
header("Content-disposition: attachment; filename=".basename($file));
echo @fileread("$file");
}
else
{
echo "No file selected";
}
This seems to work fine, however when the file is opened in Windows with notepad, the line endings are not preserved. Could anyone offer a solution to this (text files must be created with notepad)?
Thanks, Rich