coolsaurabh has asked for the wisdom of the Perl Monks concerning the following question:
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> &n +bsp; 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>  +   </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 } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: File Upload Size Check
by marto (Cardinal) on Aug 05, 2019 at 12:11 UTC | |
by coolsaurabh (Acolyte) on Aug 05, 2019 at 12:29 UTC | |
by haukex (Archbishop) on Aug 05, 2019 at 12:51 UTC | |
by coolsaurabh (Acolyte) on Aug 06, 2019 at 03:59 UTC | |
by marto (Cardinal) on Aug 06, 2019 at 06:11 UTC | |
by haukex (Archbishop) on Aug 06, 2019 at 08:53 UTC | |
by marto (Cardinal) on Aug 05, 2019 at 12:33 UTC |