
基于Laravel开发网站实时评论系统
verify_file_md5 ( $filename, $expected_md5 )
verify_file_md5: 这个WordPress函数用来验证一个文件的MD5哈希值。它检查文件的MD5哈希值是否与预期值相符,如果哈希值有效则返回真,否则返回假。
计算并比较一个文件的MD5和它的预期值。
function verify_file_md5( $filename, $expected_md5 ) { if ( 32 === strlen( $expected_md5 ) ) { $expected_raw_md5 = pack( 'H*', $expected_md5 ); } elseif ( 24 === strlen( $expected_md5 ) ) { $expected_raw_md5 = base64_decode( $expected_md5 ); } else { return false; // Unknown format. } $file_md5 = md5_file( $filename, true ); if ( $file_md5 === $expected_raw_md5 ) { return true; } return new WP_Error( 'md5_mismatch', sprintf( /* translators: 1: File checksum, 2: Expected checksum value. */ __( 'The checksum of the file (%1$s) does not match the expected checksum value (%2$s).' ), bin2hex( $file_md5 ), bin2hex( $expected_raw_md5 ) ) ); }