File downloading problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
shan123
Forum Newbie
Posts: 9
Joined: Tue Oct 21, 2003 11:04 pm

File downloading problem

Post 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;
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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
Post Reply