in reply to Re: Need to use data passed from FORM from HTML page to CGI upload script. (cgi101)
in thread Need to use data passed from FORM from HTML page to CGI upload script.

Thanks for this script. Upload function is working absolutely fine but however Download button is not available on the page.There should be Download button which should download the requested file based on the Circle and Techno selection. part of your working code

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

Download scipt

#!/usr/bin/perl #use strict; #use warnings; use CGI 'header'; use CGI::Carp qw(fatalsToBrowser); 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{Customer}; $Techno = $FORM{Techno}; $filename = $Circle.'_'.$Techno.'.csv'; my $files_location = "/opt/IBM/Maintenance/archive"; if (!$filename) { die "You must specify a file to download"; exit; } print header( -type => 'text/csv', -content_disposition => "attachment;filename=$filename", ); my $fileloc = "$files_location/$filename"; open my $fh, '<', $fileloc or Error('open', 'file', $!); print while <$fh>; close $fh or Error ('close', 'file' ); sub Error { die "@_"; }

Replies are listed 'Best First'.
Re^3: Need to use data passed from FORM from HTML page to CGI upload script. (cgi101)
by poj (Abbot) on Jul 29, 2019 at 12:43 UTC
    .. Download button is not available on the page

    It looks like is in the HTML

    <input type="submit" style="margin-left:30.5em" value="Download" onc lick="this.form.target='_blank';return true;">
    poj
Re^3: Need to use data passed from FORM from HTML page to CGI upload script. (cgi101)
by Anonymous Monk on Jul 29, 2019 at 06:26 UTC

    Hi,

    Its your code now :)

    Did you copy that %FORM stuff from use CGI or die; ? The lesson of that node is to use param()