Your suspicion, mentioned in the CB, was that the file's size was causing the problem. That's pretty likely, because you'll notice that CGI::POST_MAX is set to a pretty low number (that value is in *bytes*, by the way ... so as things stand, you'll only allow 48K total in all POSTed data.)

Other non-miscellany : rewrite this script to work under use strict, you'll thank yourself for it later.

There are also some modules that can help you make this script more portable; your "filename parsing" routine in fact only handles Win32-style delimiters => \ , but the standard (i.e. already installed) module File::Basename has robust routines that will handle the delimiters used on most operating systems. You'll need to check the $ENV{USER_AGENT} string to make an educated guess about the operating system the client is using. I do believe KM <-- follow that, by the way ... it's my way of indirectly plugging his book -- has a different strategy for dealing with handling uploads for multiple OSes, but I don't recall off the top of my head what it is.

As far as controlling the error messages, the strategy I like to use is to define a subroutine (I call it bail usually) that will get called in place of die. That way, if something fails I can intercept the error message and give the user something prettier to look at than a 500 error page. If your script is dying *within* calls to functions that are built-in or imported from modules, the usual strategy is to wrap those calls in a block-style eval, and then to check the value of the special variable $@, which will be set to the value of any error thrown by something within the eval block. A toy example:

eval { die "You're ugly, and your President dresses funny."; } if ($@) { print "Hmm, got an error message that read \"$@\" ... I wonder why? +\n"; }

Do a super search on "Exception Handling" and read the eval manual page for more info.

HTH

perl -e 'print "How sweet does a rose smell? "; chomp ($n = <STDIN>); +$rose = "smells sweet to degree $n"; *other_name = *rose; print "$oth +er_name\n"'

In reply to Re: File Upload - Complete Code by arturo
in thread File Upload - What Next? by Thathom

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.