It looks to me like you should get a copy of the actual word file uploaded. Test that by ftping the original document over in binary (NOT TEXT) mode and seeing that the two files are the same.

After that you will need to do a conversion. This is not a simple job, so don't try to figure it out for yourself. Just use a utility. A brief search turned up word2x, give that a shot and report back whether it worked. If it does not you should be able to find another conversion utility out there.

UPDATE
Having read it again, I notice that your open does not have a die on failure. That is probably because you are copying the code example. But still in a CGI script you should:

use CGI::Carp 'fatalsToBrowser';
at the top so dies go back to the user, and then in your open:
open(UPLOAD, ">$tempfile") or die "Cannot write $tempfile: $!";
You should also have some sort of locking logic for cases where two people both launch the CGI at the same time (or one person double-clicks on submit). Simple Locking shows one approach you might want to use.

In reply to RE: uploading files in CGI by tilly
in thread uploading files in CGI by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.