#!c:/perl/bin/Perl.exe
##################################
# 必要な定数の設定 #
# (場合に応じて変更する)#
##################################
$cntfname = "cnt.dat"; # カウントファイル
$lockfname = "lock.tmp"; # カウントのロックファイル
$sendfname = "send.txt"; # 送り返す内容のファイル
#################################
# 必要な変数の取得 #
#################################
#引数を取得
if ( $ENV{'REQUEST_METHOD'} eq "POST" )
{
read (STDIN, $qs, $ENV{'CONTENT_LENGTH'});
}
else
{
$qs = $ENV{'QUERY_STRING'};
}
#################################
# 出力ファイル名の作成 #
#################################
# 時分秒の取得
($sec,$min,$hour,$day,$mon,$year) = localtime(time);
$year = $year + 1900;
$mon = $mon + 1;
#カウンタの取得
open(LOCK, ">" . $lockfname);
flock(LOCK,2); #ロック
if ( -e $cntfname )
{ #カウンタファイルがある場合
open (IN, $cntfname);
$count=<IN>;
close(IN);
}
else
{ #カウンタファイルがない
$count = 0;
}
$count=$count+1;
open (OUT, ">" . $cntfname);
printf(OUT "%d",$count);
close(OUT);
close(LOCK); #アンロック後、削除
flock(LOCK,8);
unlink($lockfname);
#ファイル名作成
$outfname = "f" .$year . "_" . $mon . "_". $day . "_". $hour . "_" . $min . "_" .$sec ."NO_".$count.".txt";
#################################
# 出力ファイル書き出し #
#################################
open(OUT, ">" . $outfname);
print OUT $qs;
close(OUT);
#################################
# 結果読み込み #
#################################
$sendfname = "send.txt"; # 送り返す内容のファイル
if ( -e $sendfname )
{
$flen = -s $sendfname; # ファイルサイズ取得
open (IN, $sendfname);
read (IN, $send, $flen);
close(IN);
}
else
{
$send = "";
}
#################################
# 結果出力 #
#################################
#以下の行は、ファイルにある場合、
#削除してOK
print "Content-Type: text/plain¥n¥n";
#ここまで
print $send;
exit;
|