Hello all, I am facing strange issue in cgi script. Requirement is to upload the file and to print log message in case file size is more than 5 MB. Script is throwing error in case file size is bigger than 5 MB. However it is working fine case if the file size is less than 5 MB. Any suggestions.Pls advice.

#!/usr/bin/perl use CGI qw(:standard); use CGI::Carp qw( fatalsToBrowser ); use File::Basename; use Net::OpenSSH; use Net::SSH::Expect; use Data::Dumper; use Exporter qw(import); our @EXPORT = qw(copyToTarget); sub print_page() { print ("Content-type: text/html\n\n"); print <<__HTML__; <form name=f1 style="margin:20px 0" action="Maintenance_Framew +ork.cgi" method="post" enctype="multipart/form-data"> <p> <h3 align='center'> Maintenance File Upload </h3> <br> <p style="margin-left:16.5em;font-size:20px">Customer:<select +name="Customer" > <option value="Telenor_PK">Telenor_PK</option> <option value="Vodacom_TZ">Vodacom_TZ</option> </select> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n +bsp;&nbsp;&nbsp;&nbsp; Technology : <select name="Techno" > <option value="Core">Core</option> <option value="RAN">RAN</option> </select> </p> <br> <p>File to Upload: <input type="file" name="filecsv" /></p> <p><input type="submit" name="Submit" value="Upload"></p>&nbsp +&nbsp&nbsp </body> </html> </form> __HTML__ } sub main() { $CGI::POST_MAX = 1024 *1024 ; my $safe_filename_characters = "a-zA-Z0-9_.-"; my $upload_dir = "/opt/IBM/Maintenance/tmp"; my $query = new CGI; print_page(); my $filename = $query->param("filecsv"); my $ctext = $query->param("Customer"); my $ttechno = $query->param("Techno"); my $content_length = $ENV{'CONTENT_LENGTH'}; if ( !$filename ) { print<<END_HTML2; <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//E +N" "DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="e +n" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; ch +arset=utf-8" /> <title>Thanks!</title> <style type="text/css"> img {border: none;} </style> </head> <body> <p>File is too big for upload! $content_length</p> </body> </html> END_HTML2 exit; } else { print<<END_HTML3; <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//E +N" "DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="e +n" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; ch +arset=utf-8" /> <title>Thanks!</title> <style type="text/css"> img {border: none;} </style> </head> <body> <p>File is in relevant size to upload! $content_length +</p> </body> </html> END_HTML3 } }

In reply to File Upload Size Check by coolsaurabh

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.