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.
pojIn reply to Re^3: Need to use data passed from FORM from HTML page to CGI upload script.
by poj
in thread Need to use data passed from FORM from HTML page to CGI upload script.
by coolsaurabh
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |