Originally posted by netline5000
When I click on a word document link, it opens the Word document in my browser. However when I try to call a word document, it justs prints the code to the screen.
Don't you love it when Microsoft products are just so helpful? :rolleyes:
In that case you don't want the documents to be treated according to the browser's ideas about how they're treated. So to just treat them as bog-standard unexceptional generic files (as opposed to PDFs, or DOCs, or HTMLs):
Content-type: application/octet-stream
Content-Disposition: attachment; filename=$filename
Where the second line is so that the suggested filename in the "Save As" dialogue is the right name (and not "download.php" or whatever).
I think the second header is not handled by NS4 properly. The code I actually used (on the one occasion I've had to do this) is
header("Content-type: application/octet-stream");
$attachment=(!strstr($HTTP_USER_AGENT,"Mozilla/4") ||
strstr($HTTP_USER_AGENT,"MSIE"))?' attachment;':''; //Guess who's broken?
header("Content-Disposition:$attachment filename=$filename");
But I'm not 100% confident that the test is accurate (either not NS4 or is MSIE (both checks have to be made because some versions of IE pretend to be Netscape 4)). I have seen it working in IE, NS4, and Mozilla/NS6, however.