verify_file_md5() - WordPress 函数参考中文文档

返回介绍

verify_file_md5()

发布于 2017-09-11 字数1923 浏览 993 评论 0

verify_file_md5( string $filename,  string $expected_md5 )

Calculates and compares the MD5 of a file to its expected value.


描述


参数

$filename

(string)
(Required)
The filename to check the MD5 of.

$expected_md5

(string)
(Required)
The expected MD5 of the file, either a base64 encoded raw md5, or a hex-encoded md5


返回值

(bool|object) WP_Error on failure, true on success, false when the MD5 format is unknown/unexpected


源代码

File: wp-admin/includes/file.php

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( __( 'The checksum of the file (%1$s) does not match the expected checksum value (%2$s).' ), bin2hex( $file_md5 ), bin2hex( $expected_raw_md5 ) ) );
}

更新日志

Version 描述
3.7.0 Introduced.

相关函数

Uses

  • wp-includes/l10n.php:
    __()
  • wp-includes/class-wp-error.php:
    WP_Error::__construct()

Used By

  • wp-admin/includes/file.php:
    download_url()

User Contributed Notes

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

目前还没有任何评论,快来抢沙发吧!