filePath = $fileName; if(is_file($fileName) === true){ $this->fileSize = filesize($fileName); if($this->fileSize > 0){ $this->isFile = true; //CRC取得 $this->crc_char = $this->crc(); //CRC付加ファイルサイズ $this->fileAddCRCSize = $this->fileSize + strlen($this->crc_char); } } } ## CRC付加サイズ // @return int public function fileSize(){ if($this->isFile === false){ return 0; } return $this->fileAddCRCSize } ## CRC付加データ // @return string public function fileContents(){ if($this->isFile === false){ return null; } if($this->crc_char === null){ return $this->fileContents; }else{ return $this->fileContents . $this->crc_char; } } ## CRCチェックバリュー // @return string protected function crc(){ if($this->isFile === false){ return null; } /* データファイル オープン */ $fp = fopen($this->filePath, "rb"); /* データファイル リード */ $this->fileContents = fread($fp, $this->fileSize); if($this->fileContents === false){ return null; } $buff = unpack("C*", $this->fileContents); $crc = 0xFFFF; /* チェックバリュー計算 */ for($i = 1; $i <= $this->fileSize; $i++){ $ch = $buff[$i]; $crc = $this->crcTable[($crc >> 8 ^ $ch) & 0xFF] ^ ($crc << 8); } $crc_str = pack("n*", $crc); if($crc_str == "\x00\x00"){ return null; } return $crc_str; } } ?>