By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,286 Members | 2,364 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,286 IT Pros & Developers. It's quick & easy.

Need to download file based on user input

P: 1
Hello ,

I need to download file from the server based on user inputs.
Suppose user give the input Gabon and Core,the file name which should get downlaoded will be Gabon_Core.csv.
I tried to create below code for the same but somehow it is not working.Any help will be highly appreciated.


use CGI ':standard';
use CGI::Carp qw(fatalsToBrowser);

my $files_location;
my $ID;
my @fileholder;
my $first = $cgi->param('first_name');
my $last = $cgi->param('last_name');

print "Content-type:text/html\n\n";
print <<EndOfHTML;
<html><head><title>Generating Self-Referential URLs</title></head>
<FORM action="Maintenance_Data.cgi" method="POST">
Circle: <input type="text" name="first_name"> <br>
Technology: <input type="text" name="last_name">
<input type="submit" value="Submit">
<p>The name you entered was '$first $last'</p>
<p>The name you entered was '$file'</p>

$files_location = "/opt/IBM/netcool/gui/omnibus_webgui/etc/cgi-bin/";

#$ID = param('file');
$ID = $first . '_' . $last . '_csv';
$ID = "Gabon_Core.csv";
#print "Content-type: text/html\n\n";
#print "ID =$ID";

if ($ID eq '') {
print "You must specify a file to download.";
} else {
$fileloc=$files_location . $ID;
print "Content-Type:text/csv\n";
print "Content-Disposition:attachment;filename=$ID\r\n\n";
open(FIL,"<$fileloc") || die "Cannot open $filename, $!";
while (<FIL>) { print $_; }

Jul 3 '19 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.