Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^3: Need to use data passed from FORM from HTML page to CGI upload script.

by poj (Abbot)
on Jul 26, 2019 at 13:33 UTC ( [id://11103440]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Need to use data passed from FORM from HTML page to CGI upload script.
in thread Need to use data passed from FORM from HTML page to CGI upload script.

You can combine upload and download into one script by using an action parameter on the buttons. For example

<!DOCTYPE html> <html> <head> <title>MAINTENANCE PAGE</title> </head> <body> <form action="Maintenance_Framework.cgi" method = "post" enctype="mult +ipart/form-data"> <h3>MAINTENANCE PAGE</h3> <p> Circle: <select name="Circle" > <option value="Gabon">Gabon</option> <option value="Tanzania">Tanzania</option> </select> Technology : <select name="Techno" > <option value="Core">Core</option> <option value="RAN">RAN</option> </select> <input type="submit" name="action" value="Download"/></p> File to Upload: <input type="file" name="filecsv"/> <input type="submit" name="action" value="Upload"/> </form> </body> </html>
#!/usr/lib/perl # Maintenance_Framework.cgi use strict; use warnings; use CGI; use CGI::Carp 'fatalsToBrowser'; # debug only $CGI::POST_MAX = 1024 * 5000; my $return = 'maintenance.html'; my $upload_dir = '/opt/IBM/Maintenance/tmp'; my $q = new CGI; my $Circle = $q->param('Circle'); my $Techno = $q->param('Techno'); my $action = $q->param('action'); my $newfilename = $Circle.'_'.$Techno.'.csv'; if ($action eq 'Upload'){ my $upload_filehandle = $q->upload("filecsv"); open OUT, '>',"$upload_dir/$newfilename" or die "$!"; binmode OUT; while ( <$upload_filehandle> ) { print OUT; } close OUT; print $q->header; print << "HTM"; <html> <head><title>Maintenance Page</title></head> <body> <p>Thanks for uploading your file as $newfilename</p> <a href="$return">return</a> </body></html> HTM } elsif ($action eq 'Download'){ if (-e "$upload_dir/$newfilename"){ print "Content-Type:application/x-download\n"; print "Content-Disposition:attachment;filename=$newfilename\n\n"; open IN, '<',"$upload_dir/$newfilename" or die "$!"; while ( <IN> ) { print; } close IN; } else { print $q->header; print << "HTM2"; <html> <head><title>Maintenance Page</title></head> <body> <p>ERROR - $newfilename does not exist </p> <a href="$return">return</a> </body></html> HTM2 } } else { print $q->header; print << "HTM3"; <html> <head><title>Maintenance Page</title></head> <body> <p>ERROR - Action = '$action' </p> <a href="$return">return</a> </body></html> HTM3 }

Add security features as appropriate to your use case.

poj

Replies are listed 'Best First'.
Re^4: Need to use data passed from FORM from HTML page to CGI upload script.
by coolsaurabh (Acolyte) on Jul 26, 2019 at 15:12 UTC

    Thanks for the suggestion. I tried to execute your code but somehow when i am trying to upload file,it is giving error that File not Found. HTML Location -- > /opt/IBM/JazzSM/profile/installedApps/JazzSMNode01Cell/isc.ear/OMNIbusWebGUI.war/custom CGI Location --> /opt/IBM/netcool/gui/omnibus_webgui/etc/cgi-bin Modified HTML code

    <!DOCTYPE html> <html> <head> <title>MAINTENANCE PAGE</title> </head> <body> <form action="https://10.XXX.XXX.X:16311/ibm/console/webtop/cgi-bin/Ma +intenance_Framework.cgi" method = "post" enctype="multipart/form-data +"> <h3>MAINTENANCE PAGE</h3> <p> Circle: <select name="Circle" > <option value="Gabon">Gabon</option> <option value="Tanzania">Tanzania</option> </select> Technology : <select name="Techno" > <option value="Core">Core</option> <option value="RAN">RAN</option> </select> <input type="submit" name="action" value="Download"/></p> File to Upload: <input type="file" name="filecsv"/> <input type="submit" name="action" value="Upload"/> </form> </body> </html>
Re^4: Need to use data passed from FORM from HTML page to CGI upload script.
by coolsaurabh (Acolyte) on Jul 26, 2019 at 15:02 UTC

    I tried to use the same example which you listed but somehow when I am clicking the upload button,it is stating that Maintenance_Framework.cgi is not found. HTML page location - > /opt/IBM/JazzSM/profile/installedApps/JazzSMNode01Cell/isc.ear/OMNIbusWebGUI.war/custom CGI location - > /opt/IBM/netcool/gui/omnibus_webgui/etc/cgi-bin HTML Code for your reference which I modified in your base code

    <!DOCTYPE html> <html> <head> <title>MAINTENANCE PAGE</title> </head> <body> <form action="https://10.XXX.XXX.X:16311/ibm/console/webtop/cgi-bin/Ma +intenance_Framework.cgi" method = "post" enctype="multipart/form-data +"> <h3>MAINTENANCE PAGE</h3> <p> Circle: <select name="Circle" > <option value="Gabon">Gabon</option> <option value="Tanzania">Tanzania</option> </select> Technology : <select name="Techno" > <option value="Core">Core</option> <option value="RAN">RAN</option> </select> <input type="submit" name="action" value="Download"/></p> File to Upload: <input type="file" name="filecsv"/> <input type="submit" name="action" value="Upload"/> </form> </body> </html>

      Is

      https://10.XXX.XXX.X:16311/ibm/console/webtop/cgi-bin/Maintenance_Framework.cgi
      a valid URL if you enter it directly in the browser ?

      poj
        Yes.Absolutely. It is working successfully in original 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> &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>

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11103440]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2024-04-19 13:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found