in reply to Forcing a Word Document to Download

Is there a cool Perl way to do this?

You could write a CGI script something like this:

#!/usr/bin/perl -w use strict; my $real_doc = 'path/to/actual/document.doc'; open WORD, '<', $real_doc or die "$real_doc: $!\n"; print "Content-type: application/octet-stream\n\n"; print while <WORD>;
I don't know how "cool" that is... You might want to name it "word.doc" so that the browser tries to save it with a useful name.

More seriously, The Right Way To Do It™ (for some notion of "right") is to change the mime-type in your server configuration. Of course, what's actually done with the data is up to the browser anyway.

Why do you want to do this? If you want to provide separate links for "read it online" and "download it" you might want to consider just zipping the document up and providing a link to the zipped version for download.

-sauoq
"My two cents aren't worth a dime.";

Replies are listed 'Best First'.
Re: Re: Forcing a Word Document to Download
by sgifford (Prior) on Jul 11, 2003 at 02:02 UTC

    I don't have a Windows box handy to test with, but I'm fairly certain this won't work. When Windows/IE sees that it's got a generic octet stream to work with (and sometimes even when it doesn't), it will use the filename extensions to determine the document type.

    For this to work, then, you would have to also change the filename to something other than .doc, package it into a ZIP file and have the user unzip it, or convince your users to use a browser other than Internet Explorer.

      I don't doubt for a second that you are right. That's why I included the caveat:

      "Of course, what's actually done with the data is up to the browser anyway."

      -sauoq
      "My two cents aren't worth a dime.";