Page 1 of 1

header("Content-Type... for MS Word document

Posted: Wed Mar 12, 2003 7:28 pm
by Bill H
To use header to download a MS Word file, what would the content type be?
And would you use the size of the file in bytes for the "Content-Length" header?

Posted: Thu Mar 13, 2003 2:27 am
by volka
mime-type: application/msword. That's what associated with .doc on my system and it asks me to insert the office setup cd if I open a .doc ;)
Content-length: yes.

Posted: Thu Mar 13, 2003 8:47 am
by Bill H
Thanks. This isn't actually client side since it deals with downloading a file from a server, but that was not clear in my post.

Code: Select all

<?php
header("Content-Type: application/msword");
header("Content-Disposition: attachment; filename=$filename.doc");
readfile('$filename.doc');
?>
The documentation that I could find for Content-Type is spotty, and I wasn't getting this to work right.

Posted: Thu Mar 13, 2003 3:10 pm
by volka
readfile('$filename.doc');
there is no variable substitution within single quoted strings.
try

Code: Select all

...
header('Content-length: '.filesize("$filename.doc"));
readfile("$filename.doc");

Posted: Thu Mar 13, 2003 4:25 pm
by fractalvibes
Look here:
ftp://ftp.isi.edu/in-notes/iana/assignm ... dia-types/

for a list of many different mime types.

Phil J.

Posted: Thu Mar 13, 2003 5:54 pm
by Bill H
volka, I had the actual filename in there but didn't feel like showing it on this forum out of client confidentiality concerns.
I just didn't change the single quotes when I changed the "whatever" to "$filename".
The Content-Type you gave me fixed my problem perfectly. Thanks.