Page 1 of 1

File downloading problem

Posted: Tue Oct 21, 2003 11:04 pm
by shan123
I am trying to download a word document on the server through PHP. I'm using the foll. code . But the downloaded file outputs some garbage data.
Can anyone please help me?

Thx. in advance

$saveasname = basename($filename);

$fileContents = file_get_contents($filename);

if (preg_match('/MSIE 5.5/', $browser)
|| preg_match('/MSIE 6.0/', $browser))
{
header('Content-Disposition: filename="'.$saveasname.'"');
}
else
{
header('Content-Disposition: attachment; filename="'.$saveasname.'"');
}

//header("Content-Disposition: attachment; filename=".$fileName);
header("Content-Transfer-Encoding: binary");
header("Content-Type: application/octet-stream; name=".$filename);

echo($fileContents);

exit;

Posted: Wed Oct 22, 2003 2:35 am
by volka
is the garbage the content of the downloaded file (not saved but displayed)?
IE can handle header('Content-Disposition: attachment; filename="'.$saveasname.'"'); as well. There should be no need to differentiate here