Hi

Remember Re: Need to print file contents on page (cgi101)?

Why all the "()" in "sub name() {..." ?

I fix for you

#!/usr/bin/perl -- ## ## ## ## perltidy -olq -csc -csci=10 -cscl="sub : BEGIN END if while for " +-otr -opr -ce -nibc -i=4 -pt=0 "-nsak=*" ## #!/usr/bin/perl -- use CGI::Carp qw( fatalsToBrowser ); use strict; use warnings; use CGI (); main( @ARGV ); exit( 0 ); sub main { # return DebugCGI(); $CGI::POST_MAX = 1024 * 5000; my $upload_dir = 'goner'; my $query = CGI->new; my( $headers, $body ) = SaveUploadsTo( $query, $upload_dir ); print $headers, $body; } ## end sub main sub SaveUploadsTo { my( $query, $upload_dir ) = @_; return $query->header, PrintPage( $query ) if not $query->first_param( "filecsv" ); my $filename = WashFilename( $query->first_param( "filecsv" ) ); ## imaginary alternative # my( $filename, $error ) = WashFilename( $query->first_param( "fil +ecsv" ) ); # $error and return $query->header, ErrorPage( $query, $error ); my $tmpfilename = $query->tmpFileName( $query->first_param( "filec +sv" ) ); $tmpfilename or return $query->header, ErrorPage( $query, "No file uploaded" +); $filename = "$upload_dir/$filename"; require File::Copy; File::Copy::copy( $tmpfilename, $filename ) or die "Copy to ( $filename ) failed: (( $! ))(( $^E ))"; return $query->header, ThanksPage( $query ); } ## end sub SaveUploadsTo sub ErrorPage { my( $query, $message ) = @_; return qq{<!DOCTYPE html> <html lang="en"> <title> Error </title> <h1> $message </h1> } } ## end sub ErrorPage sub CGI::first_param { return my( $first ) = CGI::multi_param( @_ ); } sub DebugCGI { my( $cgi ) = @_; $cgi ||= CGI->new; binmode STDOUT, ':encoding(UTF-8)'; $cgi->charset( 'UTF-8' ); print $cgi->header( -charset => 'UTF-8' ); print $cgi->start_html, $cgi->b( rand time, ' ', scalar gmtime ), '<table border="1" width="%100"><tr><td>', $cgi->Dump, '</td>', '<td><div style="white-space: pre-wrap; overflow: scroll;">', $cgi->escapeHTML( DD( $cgi ) ), '</div></td></tr></table>', CGI->new( \%ENV )->Dump, $cgi->end_html; } ## end sub DebugCGI sub DD { require Data::Dumper; return scalar Data::Dumper->new( \@_ )->Indent( 1 )->Useqq( 1 )->D +ump; } sub WashFilename { use File::Basename; my $basename = basename( shift ); # untainted , only use a-z A-Z 0-9 and dot and dash $basename = join '', $basename =~ m/([\-.a-zA-Z0-9])/g; # basename is now, hop0efully, file.ext ## so to ensure uniqueness, we adulterate it :) my $id = $$ . '-' . time; my( $file, $ext ) = split /\./, $basename, 2; return join '.', grep defined, $file, $id, $ext; } ## end sub WashFilename sub ThanksPage { my( $query ) = @_; q{ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-s +trict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Thanks!</title> <style type="text/css"> img {border: none;} </style> </head> <body> <p>Thanks for uploading your file!</p> </body> </html> } } ## end sub ThanksPage sub MaintenancePage { q{<!DOCTYPE html> <html> <head> <title>MAINTENANCE PAGE</title> </head> <body> <form name = f1 action="https://10.XXX.XXX.X:16311/ibm/console/webtop/ +cgi-bin/download_csv.cgi" method = "POST"> <p style="margin-left:10em;font-size:40px">MAINTENANCE PAGE</p> <br> <p style="margin-left:16.5em;font-size:20px">Circle:<select name="Circ +le" > <option value="Gabon">Gabon</option> <option value="Tanzania">Tanzania</option> </select> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs +p;&nbsp;&nbsp; Technology : <select name="Techno" > <option value="Core">Core</option> <option value="RAN">RAN</option> </select> </p> <br> <input type="submit" style="margin-left:30.5em" value="Download" onc +lick="this.form.target='_blank';return true;"> &nbsp;&nbsp;&nbsp; <input type="submit" value="Upload" onclick="f1.action='https://10.XXX +.XXX.X:16311/ibm/console/webtop/cgi-bin/Maintenance_Framework.cgi'; +return true;"> </form> </body> </html> }; } ## end sub MaintenancePage sub PrintPage { my( $q ) = @_; <<'__HTML__'; <!DOCTYPE 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>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__ } ## end sub PrintPage

In reply to Re: Need to use data passed from FORM from HTML page to CGI upload script. (cgi101) by Anonymous Monk
in thread Need to use data passed from FORM from HTML page to CGI upload script. 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.