#!/../../usr/bin/perl #!/usr/bin/perl #!/bin/sh # # img_count.cgi # # (C) Kaoru Fujita # use lib './lib'; require 'util.pl'; # # 定数 # $Title = 'イメージカウンタ サンプルプログラム'; $Location = './tmp'; $File = $Location.'/img_count'; $ImgLoc = './images'; $ImgType = 'gif'; *data = parseInput(); # テスト用 #$data{'Col'} = '1'; $col = $data{'Col'}; if (-e $File) { openLock(CNT, "+<$File") or exitError("ファイル $File がオープンできません。"); $count = ; seek(CNT, 0, 0); } else { openLock(CNT, ">$File") or exitError("ファイル $File が作成できません。"); $count = 0; } # 1の位のときだけカウントアップ $count++ if ($col == 1); print CNT $count; closeUnlock(CNT, $File); @num = split(//, $count); # 各桁を取り出す @num = reverse(@num); # 桁を配列のインデックスに対応させる # ために逆順に並べる # 桁数以上のところは 0 とする $num = defined($num[$col-1]) ? $num[$col-1] : 0; sendImage($num); exit(0); sub sendImage { my($number) = @_; # イメージファイルのオープン open(IMG, "$ImgLoc/$number.$ImgType") or exitError(qq(ファイル $ImgLoc/$number.$ImgType がオープンできません。)); # Windows のようなバイナリとテキストを区別する場合は # テキストモードでは \r\n が \n に変換されてしまうのを # 避ける。UNIX では意味がない。 binmode IMG; binmode STDOUT; # イメージの出力 print qq(Content-type: image/$ImgType\n\n); print while (); # イメージファイルのクローズ close(IMG); } #--End of img_count.cgi