php hash_file

string hash_file ( string $algo , string $filename [, bool $raw_output = FALSE ] )

参数 ¶

algo

要使用的哈希算法的名称,例如:"md5","sha256","haval160,4" 等。

filename

要进行哈希运算的文件路径。支持 fopen 封装器。

raw_output

设置为 TRUE,输出格式为原始的二进制数据。 设置为 FALSE,输出小写的 16 进制字符串。

返回值 ¶

如果 raw_output 设置为 TRUE, 则返回原始二进制数据表示的信息摘要, 否则返回 16 进制小写字符串格式表示的信息摘要。

范例 ¶

Example #1 使用 hash_file()

<?php
/* 创建一个要计算哈希值的文件 */
file_put_contents('example.txt', 'The quick brown fox jumped over the lazy dog.');

echo hash_file('md5', 'example.txt');
?>

用于文件验证文件完整性,防止文件被篡改

猜你喜欢

转载自www.cnblogs.com/bjxing/p/10075416.html