Link to home
Create AccountLog in
Avatar of snakeriver
snakeriver

asked on

Header download of word doc is jumbled

Hello,

I'm trying to send a file to a browser.  The file type is a word doc.  When the word doc downloads, and I try to open it, the text is all jumbled.  This code works fine for pdf's and images by changing the Content-Type accordingly...
if(!is_file($fullpath)) {
  exit('File not found');
}
 
header('Cache-control: private');
header('Pragma: public');
header('Content-Type: application/msword');
header('Content-Length: ' . filesize($fullpath));
header("Content-Transfer-Encoding: binary");
header('Content-Disposition: attachment; filename="' . urldecode($path) . '"');
 
flush();
 
$file = fopen($fullpath, 'r');
while (!feof($file))
{
	print fread($file, filesize($fullpath));
	
	flush();
}
fclose($file);

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of rdivilbiss
rdivilbiss
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of snakeriver
snakeriver

ASKER

THanks rdivilbiss, I found what the problem was.  I was including a file at the top of my page, and in that include file, there were two php statements seperated by a space:

<?php
code here...
?>

<?php
code here...
?>

I got rid of the space between the two, and it works just fine.  I guess it was just putting an extra line break before the header output...