Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

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

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


in reply to Need to use data passed from FORM from HTML page to CGI upload script.

Why not select the file on the html page ?

<!DOCTYPE html> <html> <head> <title>MAINTENANCE PAGE</title> </head> <body> <form action="Maintenance_Framework.cgi" method = "post" enctype="mult +ipart/form-data"> <p>MAINTENANCE PAGE<br/> 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> </p> <br> File to Upload: <input type="file" name="filecsv"/> <input type="submit" 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 $upload_dir = '/opt/IBM/Maintenance/tmp'; my $q = new CGI; my $Circle = $q->param('Circle'); my $Techno = $q->param('Techno'); my $newfilename = $Circle.'abc'.$Techno.'.csv'; 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> </body></html> HTM
poj

Replies are listed 'Best First'.
Re^2: Need to use data passed from FORM from HTML page to CGI upload script.
by coolsaurabh (Acolyte) on Jul 26, 2019 at 12:20 UTC
    Thanks for the comment. What you suggested is absolutely correct but not as per the requirement. I need to provide another button "Download" on the HTML page wherein if user click this button , Circle_Techno.csv should get download(Basically I am calling another download cgi script here for its execution). My bad .. I forgot to write about it in the original post.

      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>

      Add security features as appropriate to your use case.

      poj

        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>

        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>

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2024-04-25 09:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found