Hey

I'm having some trouble setting the maximum file size allowed to upload.

Here is my upload portion of the script:

use CGI; $CGI::POST_MAX = 1536000; #1.5MB my $upload_dir = "C:/Web Sites/Projects/Uploading/datapath"; my $business_plan_file = $results->valid('file_name'); #I'm using Data::FormValidator, $results->valid('file_name') is th +e input from the upload field in my form. $business_plan_file =~ s/.*[\/\\](.*)/$1/; #retrieves filename +w/out users full path my $upload_filehandle = $results->valid('file_name'); open UPLOADFILE, ">$upload_dir/$business_plan_file" or die; binmode UPLOADFILE; while ( <$upload_filehandle> ) { print UPLOADFILE; } close UPLOADFILE;


When I attatch a large file, it still uploads the file even though its over 1.5 MB. It seems everytime I try a new module I run into these kind of newbie problems =( Can anyone tell me whats wrong with my code? Is there any way I can specify the error message if it dies if the file being uploaded is to surpasses 1.5mb?

Also, is there another way to set it so the uploads only allow a specific type of file based on its MIME type? This script will be used for only to upload Word Documents and Excel files. One way I thought about doing this is to split the filename and retrieve the extension, but then again that is not the safest way.

Thank you,
Anthony

In reply to Setting max upload size/MIME types by perleager

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.