lethered has asked for the wisdom of the Perl Monks concerning the following question:

Hi. I'd like to create a cgi script that opens a document in its native application. complications: the document doesn't have an extension (which is normal for documents of this type). I've looked all over the web and haven't found an answer. Thanks for the help! Lynn
  • Comment on Opening a Document in its Native Application

Replies are listed 'Best First'.
Re: Opening a Document in its Native Application
by shmem (Chancellor) on Sep 05, 2008 at 22:59 UTC
    a cgi script that opens a document

    No such thing. A CGI script serves a document, it is up to the receiving (client) side what to do about it.

    Upon serving the document, mark it with the appropriate MIME type in the HTTP header, e.g.

    Content-type: application/msword

    You can do that with the header method/function of CGI.

Re: Opening a Document in its Native Application
by tilly (Archbishop) on Sep 05, 2008 at 23:01 UTC
    You need to send a Content-Type header back to the browser. For instance
    Content-Type: img/gif
    With CGI you can do this by passing a -type argument to the header function. Like this:
    print header( # Stuff -type => "img/gif", # more stuff );
Re: Opening a Document in its Native Application
by BrowserUk (Patriarch) on Sep 05, 2008 at 23:24 UTC
    the document doesn't have an extension (which is normal for documents of this type).

    Why not just rename it with the correct extension?

    Sounds vaguely like you're trying to fool someone into opening a document of a type they might not normally open.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
Re: Opening a Document in its Native Application
by JadeNB (Chaplain) on Sep 05, 2008 at 22:55 UTC
    If your question is 'How do I find the right application to which to dispatch?', it seems that File::MMagic might do the trick.