>>306
#!/usr/bin/perl
$|=1;

require './cgi-lib.pl';

#// SETTINGS //
$base = './data/'; #実際のファイルがあるディレクトリへのパス

&ReadParse(\%in);
$in{'filename'} =~ s/<|>|\||\\|\/|:|\?|"|\0//g;
$file = $base.$in{'filename'};
if(!-f $file){ &error(); }
@stat = stat($file);
print 'Content-Disposition: attachment; filename=', $in{'filename'}, "\n";
print 'Content-Length: ', $stat[7], "\n";
print 'Content-type: application/octet-stream', "\n\n";
open(FH, $file);
binmode(STDOUT);
while (<FH>) { print $_; }
close(FH);
exit;

sub error {
print 'Content-type: text/html', "\n\n";
print 'Error';
exit;
}