#!/usr/bin/perl -w use strict; use warnings; use CGI qw(:standard escapeHTML); use CGI::Carp qw(fatalsToBrowser); my $ausgabe = ""; my $downloadaufruf = ""; my $wert   = param('wert')   || ""; my $button = param('action') || ""; if ($button eq "Senden") { $ausgabe .= "...senden gedrückt...
"; $ausgabe .= "Wert = $wert
"; $downloadaufruf = "getfile('?action=Download&file=test.txt'); alert('aha');"; } elsif ($button eq "Download") {    my $file = param('file');    download($file);        exit; } my $html = <<"(END OUT HTML)"; Test
$ausgabe
(END OUT HTML) print CGI::header( -type => "text/html"), $html; 1; sub download { my $file = shift; # Zur Sicherheit my $safedir = "/hier/das/Verzeichnis/der/Downloaddateien/"; # Zur Sicherheit if ( $file =~ /^[A-Z0-9_]+\.[A-Z0-9_]+/i ) { # Dateiname besteht nur aus abcdef.extension !    $file = $safedir . $file;    print CGI::header( -type => "application/octet-stream", -attachment => $file );    open(FH,"<$file") || return undef;    binmode FH;    binmode STDOUT;    print while();    close FH;      return 1; } else {    return undef; # Fehler }     }