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

Here's the code for a cgi script I put on a windows server (script is windows compatible). The script is meant work like a regular web form with the added feature of allowing the user to upload a file from their local computer to a directory on the web server. Everything works (autoresponder email, form details email, image upload, etc) except for the fact that the uploaded images are jumbled as if they were transfered in ascii mode. code located here: http://209.41.175.182/fforms.txt
  • Comment on File Upload CGI Form on Windows problem

Replies are listed 'Best First'.
Re: File Upload CGI Form on Windows problem
by ikegami (Patriarch) on Nov 17, 2005 at 21:24 UTC
    It uses binmode on the input (good), but not on the output (bad). Try changing
    open(TMP, ">$files_path/$tm-$i.$type") || error(...); print TMP "$fl"; close TMP;
    to
    open(TMP, ">$files_path/$tm-$i.$type") || error(...); binmode(TMP); print TMP "$fl"; close TMP;
      Thank you all for taking the time to look at this... ikegami, I added the line you suggested and that fixed the problem.
Re: File Upload CGI Form on Windows problem
by johnnywang (Priest) on Nov 17, 2005 at 20:56 UTC
    It seems you're doing everything from scratch, why not use the standard modules lie CGI?
      This code is from a freeware script I found on the web.
Re: File Upload CGI Form on Windows problem
by marto (Cardinal) on Nov 17, 2005 at 21:12 UTC
    Greetings Anonymous Monk,

    Besides the advice you have already recieved I think you should read How do I post a question effectively?.
    It mentions not giving out your email address or other sensitive data.
    At first glance you may want to add the binmode(TMP) line to your code:
    open(TMP, ">$files_path/$tm-$i.$type") || error("Cannot upload file $t +m-$i$type: $!"); binmode(TMP) print TMP "$fl"; close TMP

    Let us know how you get on.
    Cheers

    Martin
Re: File Upload CGI Form on Windows problem
by ickyb0d (Monk) on Nov 17, 2005 at 21:14 UTC

    Maybe you need to use binmode on binary files, such as images.

    update: whoops, looked at code. it's using binmode.