Thread Download bricht Ladevorgang der Webseite ab (12 answers)
Opened by perli at 2005-06-27 17:53

GwenDragon
 2005-06-28 12:50
#29518 #29518
User since
2005-01-17
14628 Artikel
Admin1
[Homepage]
user image
Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/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...<br>";
$ausgabe .= "Wert = $wert <br>";

$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)";
<html><head>
<title>Test</title>
<script language=\"JavaScript\" type=\"text/javascript\"><!--
var dlwin = NULL;
function getfile(url) {
   dlwin = window.open( url, \"downloadw\", \"width=200,height=200,dependent=yes\");
}
// -->
</script>
</head>
<body onunload="if (dlwin) dlwin.close()">
<script language=\"JavaScript\" type=\"text/javascript\">
<!--
   $downloadaufruf
// -->
</script>
<noscript><h1>Der Download funktioniert nur mit Javascript!
<br>Bitte Javascript aktivieren!</h1></noscript>

<FORM METHOD="POST">
$ausgabe
<input type="text" name="wert">
<input type="submit" name="action" value="Senden">
</FORM>
</body>
</html>
(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(<FH>);
   close FH;  
   return 1;
}
else {
   return undef; # Fehler
}
   
}
NICHT lang ausgetestet!!!

Es ist möglich in einem zweiten Fenster den Download an zu stoßen, aber ... Es ist dann nicht klar, wann das Fenster wieder zu gemacht werden kann. Derzeit schließt sich das Fenster, wenn die Seite gewechselt wird.
Schließlich weiß das Javascript nicht, ob der Download beendet ist. Das ist ja nicht so wie beim Downloadfenster des Browsers.

Hmmm. Mir ist noch nichts eingefallen dazu.\n\n

<!--EDIT|GwenDragon|1119955506-->

View full thread Download bricht Ladevorgang der Webseite ab