>Does anyone know of a way to detect the fact that a file upload has exceeded the $CGI::POST_MAX limit, and hence failed, so that an error can be displayed? As the file doesn't actually get uploaded, I presume that the upload error-detection code given in the CGI module wouldn't work in this case.

I have an upload script that relies *solely* on the CGI.pm module, and the script incorporates a "maximum size" testing feature that has worked for me. Here's the snippet I use as the uploaded file is being "read in" during the upload:

$max_size = '100000'; #set your max size value $totalbytes=0; open (IMAGESAVE,">$image_upload_directory/$final_name"); while ($bytesread=read ($file,$data,1024)) { $totalbytes+=$bytesread; if ($totalbytes > $max_size) { unlink ("$image_upload_directory/$file_name"); &FileTooLarge; #call your error sub exit; } print IMAGESAVE $data; } close IMAGESAVE;
Given the level of knowledge at perlmonks, I may likely find out there's something wrong with the way I've got things set up ;), but as a said, the code above has worked for me for quite awhile.


In reply to Re: Detecting when a $CGI::POST_MAX limit is exceeded by Hagbone
in thread Detecting when a $CGI::POST_MAX limit is exceeded by Tanalis

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.