in reply to Re: Download file to browser
in thread Download file to browser

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"

Replies are listed 'Best First'.
Re^3: Download file to browser
by david.woosley (Initiate) on Apr 22, 2024 at 19:16 UTC
    That worked great. Thanks so much, folks. I appreciate your efforts more than you can imagine.

      Hopefully you read what I posted. It isn't wise to use this code 'as is'.

A reply falls below the community's threshold of quality. You may see it by logging in.