Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I have a directory of files containing nearly all types of files (sounds, images, text, html, exes) and I want to force a download for that link when they click on the link for that file. I've been told 'application/octet-stream' is how you force ANY file to download rather than load in the screen (like images typically load to screen, right?).
The link forces a download right now, but it tries to download the CGI script itself without the extension instead of the file I'm telling it to. It's requesting action on a file "filemanager" instead of let's say image.gif or sound.wav. Does anyone see where I went wrong? I am linking to in like <a href="filemanager.cgi?dl=$_">download!</a> and $_ does indeed contain what I expect it to. I've done testing to be sure my variable contains what it should, and it does.
Where did I go wrong?
# $dl_file is absolute path to uploaded directory where files are kept my $download = url_param('dl'); if ($download ne "") { if (exists $uploadedfiles{$download}) { my($file, $type, $time, $size) = split(/::/, $uploadedfiles{$down +load}); my $load_file = join("", $dl_file, $file); print header(-type=>'application/octet-stream', -attachment=>"$load_file", -expires=>'-1d'); print start_html); print end_html; exit; } else { print header, start_html("ERROR"); print qq(<center>Does not exist!</center>); print end_html; exit; } }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Force download -- Repost
by Kozz (Friar) on Apr 03, 2004 at 03:27 UTC | |
by Anonymous Monk on Apr 03, 2004 at 03:52 UTC | |
Re: Force download -- Repost
by sgifford (Prior) on Apr 03, 2004 at 08:53 UTC | |
•Re: Force download -- Repost
by merlyn (Sage) on Apr 03, 2004 at 10:48 UTC | |
|