Wie kann ich ein Download-Skript erstellen?
Inhalt:
Das Download-Skript
Auf vielen Seiten sind nicht nur Uploads, sondern auch Downloads
erwünscht. Ein ganz einfaches Skript, dies zu realisieren ist
folgendes:
#! /usr/bin/perl
use strict;
use warnings;
use CGI;
my $cgi = CGI->new();
my %params = $cgi->Vars();
download($params{file});
sub download {
my $file = shift;
$file = '../sources/'.$file;
print "Content-Type: application/octet-stream\n";
print "Content-Disposition: attachment; filename=$file\n\n";
open(FH,"<$file");# || die "mist";
binmode FH;
binmode STDOUT;
print while(<FH>);
close FH;
}
Ergänzungen, Kommentare
AlexKoeppe - 14 Jul 2003 - Alternative HTTP Header Generierung mit CGI
print $cgi->header(-type=>'application/octet-stream',-attachment=>$file);
Kommentare werden am besten in folgender Form vorgenommen, damit
sie im Inhaltsverzeichnis angezeigt werden (natürlich ohne das <verbatim>):
---+++ Main.??? - 14 Jul 2003 - Betreff