RenardBleu has asked for the wisdom of the Perl Monks concerning the following question:

Solved : answer can be found here : http://stackoverflow.com/questions/24673182/perl-overload-file-name-download I had an error in my regexp but since the download was OK, i never suspected the regexp to mess it all :/ -- Hi monkers, I need to be able to propose files to ba downloaded but i have to read and print the file in my CGI. I tried to go for :
#!/usr/bin/perl -w use strict; push( @INC, $lib_directory ); require 'lib_utils.pl'; dl_file('/tmp/final.pdf');
as main page (dl.pl) and
sub dl_file { my ($file) = @_; if ( ! -e $file) { print "file does not exist"; return 0; } my $content = read_file( $file, binmode => ':utf8' ) ; $file =~ m#(.*)([^/]*)$#; my $directory = $1; my $filename = $2; `echo $directory$filename >> /tmp/flag2`; chdir $directory; my $form = new CGI; print $form->header( -type => 'application/octet-stream', -attachment => $filename, -filename => $filename, -Content-Disposition => "attachment; filename=$filename", ); $form->print($content); return 1; }
for the called function Funny thing is, this code workes just fine if i dont go for a sub and have all the code in dl.pl BUT as soon as i move the code in a sub, the downloaded file is called after the script (ie dl.pl) How would you change it or how would you do ? Thanks in advance for your help

Replies are listed 'Best First'.
Re: Overloading the name of a proposed download
by Anonymous Monk on Jul 10, 2014 at 09:32 UTC
Re: Overloading the name of a proposed download
by kennethk (Abbot) on Jul 10, 2014 at 13:41 UTC

    Obligatory xkcd: xkcd://1171


    #11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

Re: Overloading the name of a proposed download
by Preceptor (Deacon) on Jul 10, 2014 at 16:17 UTC

    Bah, you could have at least let me comment here too, and claim the credit twice!