I've been away from Perl for almost 3 months now. One of my first tasks, now that I'm back, is to create a file upload script. That's not a problem. I've done enough of these that I can code them in my sleep.

Wrong.

What am I missing with the following test case?

#!D:\perl\bin\perl.exe -T use strict; use warnings; use CGI; use HTML::Entities; use constant UPLDTMPDIR => './newDocs/'; use constant ZIPTEMPFILE => 'zip~tempfile.zip'; $CGI::DISABLE_UPLOAD = 0; # Temporarily reenable uploads $CGI::POST_MAX = 1_048_576; my $cgi = CGI->new; print $cgi->header, $cgi->start_html( -title => "Test" ); get_upload(); print $cgi->h1( "It worked. Stop whining and get this done!" ), $cgi->end_html; sub get_upload { $cgi->cgi_error and error( "Error uploading file: " . $cgi->cgi_er +ror ); my $zipFile = $cgi->upload( "zipfile" ) or error( $cgi->p( "No fil +e uploaded." ) ); my $format = $cgi->uploadInfo( $zipFile )->{ 'Content-Type' }; if ( $format ne 'application/x-zip-compressed' ) { error($cgi->p( "Illegal file format." ) ); } open FH, ">", UPLDTMPDIR.ZIPTEMPFILE or die "Can't open ".UPLDTMPDIR.ZIPTEMPFILE." for writing: $!" +; { local $/; binmode $zipFile; print FH <$zipFile>; } close FH or die "Can't close ".UPLDTMPDIR.ZIPTEMPFILE.": $!"; }

Everything works perfectly, but I am uploading a zip file that is 31,113 bytes. It's getting saved as 31,217 bytes. When I try to unzip the archive, it's identified as a corrupted. My only guess is that the line endings are being translated, but I thought binmode would take care of that. Heck, I'm embarrassed to be asking this because it's usually the sort of question that I answer :)

Configuration info:

Cheers,
Ovid

Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.


In reply to Yet another file uploading problem. by Ovid

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.