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

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
Bill H
DevNet Resident
Posts: 1136
Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:

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

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

Post 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.
User avatar
Bill H
DevNet Resident
Posts: 1136
Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:

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

Post 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");
fractalvibes
Forum Contributor
Posts: 335
Joined: Thu Sep 26, 2002 6:14 pm
Location: Waco, Texas

Post by fractalvibes »

Look here:
ftp://ftp.isi.edu/in-notes/iana/assignm ... dia-types/

for a list of many different mime types.

Phil J.
User avatar
Bill H
DevNet Resident
Posts: 1136
Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:

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