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

Im pretty new to perl so go easy on me... Im using perl version 5.004_05 and basically i want to open a word document when a user clicks a link in the browser. Having done some research it seems the way to do this is to use the Win32 module, however I dont have this. So is there another way I can open a word document in the version of perl im using? thanks

Replies are listed 'Best First'.
[OT] Re: how do i open a word doc?
by trammell (Priest) on Mar 03, 2005 at 16:41 UTC
    ... (I) want to open a word document when a user clicks a link in the browser.

    This doesn't require Perl; you need to make sure that the webserver is supplying the right MIME type for the .doc file (application/msword should work), and make sure the browser has a handler installed for that MIME type.

Re: how do i open a word doc?
by inman (Curate) on Mar 03, 2005 at 16:43 UTC
    Are you trying to create a link in a Perl generated web page that the users can download and open a word document?

    Firstly you need to make sure that the word doc is in a directory that is being published by the web server (IIS?) and then provide a link to it e.g http://www.mydomain.com/docs/my.doc

Re: how do i open a word doc?
by JediWizard (Deacon) on Mar 03, 2005 at 16:47 UTC

    I'd like a little clarification here. I assume, given that you want this activiated by a link in a browser, that we have a client/server situation here. Do you want the word document to open on the client computer, or do you want to open and read a word document with your perl code? Is the word document on the client computer, or on the server?

    If you want a word document which resides on the server to be opened on the client machine, as simple link with a http url path to the document will work. If the word document is on the clients machine, you can use a link with a file:// and a path to the document.

    <a href="http://your.server/path/to/word.doc">click here</a> <a href="file://C:/path/to/word.doc">click here</a>

    If you were running your perl code on the client side, via a gui or perl script embedded in html, I suppose you could use Win32::OLE to start word, and make it open a document, but I would think it would be easier to use simple links in a browser.

    I hope this is helpfull, let me know if there is anything which remain unclear.

    May the Force be with you
Re: how do i open a word doc?
by Anonymous Monk on Mar 04, 2005 at 08:26 UTC

    Basically the word documents I want to open will be stored locally, not sure where exactly yet but for now lets assume its on the users c: drive. I tried using a link to the file but as it’s a .doc extension it doesn’t seem to recognise it, I changed the file to a .txt extension and it opened it up in the browser.(so it recognises .txt but not .doc)

    I assume its not recognising the .doc format and I have to tell it this somehow. However I don’t have access to the Win32 module as we are using an earlier version of Perl. So I guess im asking if there is a way I can get round this. The script I’m running is a perl script that just outputs data in a table and I want one of these cells to be the link to the file.

    At the moment if I say

    <td><ahref="c:/worddoc.doc">Link</a></td>
    When I click the link I just get a blank page.

    My preference would be to have the document actually open up in word on the client side. Being new to Perl im just trying out a few ways of doing things but not getting very far. (the force is not strong in this one…. yet)

    Hopefully that clarifies things.

    Many thanks for your help so far.

    20050304 Janitored by Corion: Fixed formatting, added code tags. Please preview before you post

      You cannot create link to file on the client's machine, thank goodness. That would be a BIG security issue.


      holli, /regexed monk/
Re: how do i open a word doc?
by Anonymous Monk on Mar 04, 2005 at 10:35 UTC
    Do you mean I shouldn't create a link to a file on the client server or there is no way that it will work?
      i meant on the client side . duh.. ah well its early
        The latter. There is no way.

        Do you know that you can update you nodes?


        holli, /regexed monk/
Re: how do i open a word doc?
by InfiniteLoop (Hermit) on Mar 03, 2005 at 16:53 UTC
    As suggested elsewhere here, let the client (Browser) do the work for you. Easiest way is a link to the file (don't forget to name the file with .doc extension, other wise browsers get confused, mostly) or if you don't want to provide a link (may be you have the file in your database), write the appropriate headers (content-type: application/octet-stream , im not sure on this one though) and print the file to the client (browser)

      content-type: application/octet-stream means "Well, uh, its some bytes". Not recomended for Word documents, for which the correct content type is: application/msword.

      Sometimes people use octet-stream to prompt user agents to save the file rather then opening it, but the correct way to handle that is via the content-disposition header.

Re: how do i open a word doc?
by Anonymous Monk on Mar 04, 2005 at 08:28 UTC

    At the moment if I say

    <ahref="c:/worddoc.doc">Link</a></td>

    When I click the link I just get a blank page.

    My preference would be to have the document actually open up in word on the client side. Being new to Perl im just trying out a few ways of doing things but not getting very far. (the force is not strong in this one…. yet)

    Hopefully that clarifies things anyway.

    Many thanks for your help so far.

    20050304 Janitored by Corion: Added formatting, added code tags. Please preview before you post and read the Writeup Formatting Tips

Re: how do i open a word doc?
by Anonymous Monk on Mar 04, 2005 at 08:31 UTC
    excuse all the repeated lines, my comment didnt appear to be posting correctly
Re: how do i open a word doc?
by Anonymous Monk on Mar 04, 2005 at 11:15 UTC
    no i didnt know i could do that, but then this is the first time iver used a forum. Does everyone else think there is no way I can achieve waht im trying to achieve?
Re: how do i open a word doc?
by Anonymous Monk on Mar 03, 2005 at 16:43 UTC
    thanks ill try it
Duplicate: Re: how do i open a word doc?
by Anonymous Monk on Mar 04, 2005 at 08:30 UTC
    At the moment if I say
    <td><ahref="c:/worddoc.doc">Link</a></td>
    When I click the link I just get a blank page. My preference would be to have the document actually open up in word on the client side. Being new to Perl im just trying out a few ways of doing things but not getting very far. (the force is not strong in this one…. yet) Hopefully that clarifies things anyway. Many thanks for your help so far.