coolsaurabh has asked for the wisdom of the Perl Monks concerning the following question:
I have requirement where user need to select Circle and Technology on HTML page and then should click Upload button.Once user will click Upload button,Upload CGI will be called where user will get option to upload the file on server. Now whatever the file user uploads that has to be renamed after combining Circle and Technology value received from HTML page.I am struggling to fetch Circle and Technology value in Upload script. Pls really need your suggestion here.
HTML Code
<!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> &nbs +p; 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;"> <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>
UPLOAD CGI SCRIPT
#!/usr/bin/perl use CGI qw(:standard); use CGI::Carp qw( fatalsToBrowser ); use File::Basename; use Exporter qw(import); our @EXPORT = qw(copyToTarget); $newfilename=''; sub xyz() { local ($buffer, @pairs, $pair, $name, $value, %FORM); $ENV{'REQUEST_METHOD'} =~ tr/a-z/A-Z/; if ($ENV{'REQUEST_METHOD'} eq "POST") { read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); } else { $buffer = $ENV{'QUERY_STRING'}; } @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%(..)/pack("C", hex($1))/eg; $FORM{$name} = $value; } $Circle = $FORM{Circle}; $Techno = $FORM{Techno}; $newfilename = $Circle.'abc'.$Techno.'.csv'; print ("Content-type: text/html\n\n"); print <<_ABC_; <p>$newfilename</p> _ABC_ } sub print_page() { # xyz(); 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>File to Upload: <input type="file" name="filecsv" /></p> <p><input type="submit" name="Submit" value="Upload"></p>  +   </body> </html> </form> __HTML__ } sub main() { #xyz(); $CGI::POST_MAX = 1024 * 5000; 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"); if ( !$filename ) { exit; } my ( $name, $path, $extension ) = fileparse ( $filename, '.csv +' ); $filename = $name . $extension; $filename =~ tr/ /_/; $filename =~ s/[^$safe_filename_characters]//g; if ( $filename =~ /^([$safe_filename_characters]+)$/ ) { $filename = $1; } else { die "Filename contains invalid characters"; } my $upload_filehandle = $query->upload("filecsv"); open ( UPLOADFILE, ">$upload_dir/$filename" ) or die "$!"; binmode UPLOADFILE; while ( <$upload_filehandle> ) { print UPLOADFILE; } close UPLOADFILE; print <<END_HTML; <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/ +xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang= +"en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=ut +f-8" /> <title>Thanks!</title> <style type="text/css"> img {border: none;} </style> </head> <body> <p>Thanks for uploading your file!</p> </body> </html> END_HTML } main();
|
|---|