ファイルへ保存ダイアログを表示
どのようなファイルもダイアログによりファイルのダウンロードを行う
aaa.txt(ダウンロード対象データ)
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
cccccccccccccccccccccccccccccccccccccccccccc
test07.cgi
#!"C:/Perl64/bin/perl.exe"
use strict;
use warnings;
print "Content-Type: text/html\n\n";
# タイトル
my $title = "テストタイトル";
my $data = "テスト Hello World";
print <<HTML_EOF;
<html>
<head>
<title>$title</title>
</head>
<body>
<div>
$data
</div>
<hr />
<div>
<a href="./test08.cgi">ダウンロード</a>
</div>
HTML_EOF
print "</table>";
print <<HTML_EOF;
</body>
</html>
HTML_EOF
test08.cgi
#!"C:/Perl64/bin/perl.exe"
use strict;
use warnings;
# ファイル名
my $file = "D:/Tools/Works/websystem/testweb02/cgi-bin/aaa.txt";
my $downloadFile = "download.dat";
#ダウンロードファイルオープン
open (DF, "<$file") or die "cannot open '$!'";
#ヘッダー部ダウンロード
print <<"HERE1";
Content-type: application/octet-stream
Content-Disposition: attachment; filename=$downloadFile
HERE1
#本体ダウンロード
binmode DF; # 開いたファイルをバイナリモードへ
binmode STDOUT; # 標準出力をバイナリモードへ
# 改行ごとに出力を行う
while (my $DFdata = <DF>) {
print STDOUT $DFdata; # 標準出力で出力
}
#ダウンロードファイルクローズ
close DF;
結果画像
リンク表示
ダウンロードダイアログ
最終更新:2012年01月18日 21:48