指定のファイルのを出力
テキストを出力
aaa.txt(テキストデータ)
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
cccccccccccccccccccccccccccccccccccccccccccc
test08a.cgi
#!"C:/Perl64/bin/perl.exe"
use strict;
use warnings;
# ファイル名
my $file = "D:/Tools/Works/websystem/testweb02/cgi-bin/aaa.txt";
my $downloadFile = "download.csv";
my $size = -s $file;
#ダウンロードファイルオープン
open (DF, "<$file") or die "cannot open '$!'";
### Content-type: application/octet-stream
### Content-Disposition: attachment; filename=download.dat
### Content-Length: 146
#ヘッダー部ダウンロード
print <<"HERE1";
Content-type: text/plain;name=$downloadFile
Content-Length: $size
HERE1
#本体ダウンロード
binmode DF; # 開いたファイルをバイナリモードへ
binmode STDOUT; # 標準出力をバイナリモードへ
# 改行ごとに出力を行う
while (my $DFdata = <DF>) {
print STDOUT $DFdata; # 標準出力で出力
}
#ダウンロードファイルクローズ
close DF;
結果画面
リンク
テキストを出力
XMLを出力
bbb.xml(テキストデータ)
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<root>
<item1>項目1</item1>
<item2>項目2
<sub1>サブ項目1</sub1>
<sub2>サブ項目2</sub2>
</item2>
<末尾>以上です(03/8/7)</末尾>
</root>
test08b.cgi
#!"C:/Perl64/bin/perl.exe"
use strict;
use warnings;
# ファイル名
my $file = "D:/Tools/Works/websystem/testweb02/cgi-bin/bbb.xml";
my $size = -s $file;
#ダウンロードファイルオープン
open (DF, "<$file") or die "cannot open '$!'";
### Content-type: application/octet-stream
### Content-Disposition: attachment; filename=download.dat
### Content-Length: 146
#ヘッダー部ダウンロード
print <<"HERE1";
Content-type: text/xml;
HERE1
#本体ダウンロード
binmode DF; # 開いたファイルをバイナリモードへ
binmode STDOUT; # 標準出力をバイナリモードへ
# 改行ごとに出力を行う
while (my $DFdata = <DF>) {
print STDOUT $DFdata; # 標準出力で出力
}
#ダウンロードファイルクローズ
close DF;
リンク
XMLを出力
画像を出力
ccc.jpg(画像データ)
test08c.cgi
#!"C:/Perl64/bin/perl.exe"
use strict;
use warnings;
# ファイル名
my $file = "D:/Tools/Works/websystem/testweb02/cgi-bin/ccc.jpg";
my $downloadFile = "download.csv";
my $size = -s $file;
#ダウンロードファイルオープン
open (DF, "<$file") or die "cannot open '$!'";
### Content-type: application/octet-stream
### Content-Disposition: attachment; filename=download.dat
### Content-Length: 146
#ヘッダー部ダウンロード
print <<"HERE1";
Content-type: image/jpeg;name=$downloadFile
Content-Length: $size
HERE1
#本体ダウンロード
binmode DF; # 開いたファイルをバイナリモードへ
binmode STDOUT; # 標準出力をバイナリモードへ
# 改行ごとに出力を行う
while (my $DFdata = <DF>) {
print STDOUT $DFdata; # 標準出力で出力
}
#ダウンロードファイルクローズ
close DF;
結果画面
リンク
画像を出力
最終更新:2012年01月18日 22:23