| Description: | Ever want a cgi program to offer a list of files for a user to accept or cancel? This will open the Download Dialog Box for a list of files. |
#!/usr/bin/perl
use warnings;
use strict;
my $boundary_string = "\n" . "--End" . "\n";
my $end_of_data = "\n" . "--End--" . "\n";
my @file_list = ("test.tgz","test1.tgz","test2.tgz");
print<<EOH;
Content-type: multipart/x-mixed-replace\;boundary=End
EOH
foreach my $file (@file_list){
&send_file ($file);
print $boundary_string;
}
print $end_of_data;
exit(0);
sub send_file {
my $file = $_[0];
if (open (FILE, "< $file")) {
print<<EOF;
Content-type: application/octet-stream
Content-Disposition: attachment\; filename=$file
EOF
binmode FILE;
print <FILE>;
close (FILE);
}else{print "Cannot open file $file!"}
}
|
|
| comment on cgi-multi-download Download Code | |
|---|---|
| •Re: cgi-multi-download by merlyn on Jul 15, 2002 at 19:06 UTC | |
use CGI qw(:push);
@ARGV = ("test.tgz","test1.tgz","test2.tgz");
$/ = undef;
print multipart_init();
while (<>) {
print multipart_start("application/octet-stream");
print $_;
print multipart_end();
}
print multipart_final();
| [reply] d/l code |