verify_file_md5
函数
verify_file_md5 ( $filename, $expected_md5 )
- 参数
-
-
(string)
$filename
The filename to check the MD5 of.- Required: 是
-
(string)
$expected_md5
The expected MD5 of the file, either a base64-encoded raw md5, or a hex-encoded md5.- Required: 是
-
(string)
- 返回值
-
- (bool|WP_Error) True on success, false when the MD5 format is unknown/unexpected, WP_Error on failure.
- 定义位置
-
-
wp-admin/includes/file.php
, line 1318
-
wp-admin/includes/file.php
- 引入
- 3.7.0
- 弃用
- –
Calculates and compares the MD5 of a file to its expected value.
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 ) ) ); }
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。