php,perl计算crc
PHP版:
<?php echo getCrc32("/var/www/html/resource/koc_data/2013_03/01/1ck65e.koc") ; # php获取crc32 function getCrc32($filename) { if( !file_exists($filename) ) return "0" ; $fileSize = filesize($filename); if( 0 == $fileSize ) return "0" ; $fileString = file_get_contents($filename) ; $crc = strtoupper( dechex( crc32($fileString) ) ); $ret = $crc."_".$fileSize; return $ret; } ?>
Perl:
# 需要先安装 String::CRC32 use String::CRC32; sub getCrc{ open my $fd , '<' , $filepath or die("error"); my $crc2 = crc32($fd); my $crc_out = sprintf("%x", $crc2); print uc($crc_out) ; }