Why do you call print with brackets then again without?
print ("Content-Type:application/x-download\n"); print "Content-Disposition: attachment; filename=$file\n\n";
Update: Looks like a copy/paste from SO https://stackoverflow.com/questions/15294815/perl-cgi-to-download-a-file-via-web-browser:
use CGI; my $html= new CGI; #get the file name from URL ex. http://<server_IP>/cgi-bin/download.cg +i?a=testing.txt my $file= $html->param('a'); # $file is nothing but testing.txt my $filepath= "/var/www/upload/$file"; print ("Content-Type:application/x-download\n"); print "Content-Disposition: attachment; filename=$file\n\n"; open FILE, "< $filepath" or die "can't open : $!"; binmode FILE; local $/ = \10240; while (<FILE>){ print $_; } close FILE; # use Unlink if u want to delete the files after download. #unlink ($filepath);
Ignoring the comment from davorg:
"Oops. I moved the articles around a bit. The link is not dead; it tells you where to go - perlhacks.com/articles/cgi-programming/cgi-programming-part-2. But to summarise, if I send you a file parameter of "../../../etc/passwd", you send me the file that contains all of your passwords for me to crack at my leisure. – Dave Cross Jan 19, 2017 at 5:56"
In reply to Re^2: Download file to browser
by marto
in thread Download file to browser
by david.woosley
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |