hash_update_file
从文件向活跃的哈希运算上下文中填充数据
此函数适用于 PHP 5.1.2 及以上版本。
hash_update_file 函数用于更新一个哈希上下文对象的哈希值。通过该函数,您可以将文件的内容加入到现有的哈希上下文中,继续计算文件内容的哈希值。
bool hash_update_file ( resource $context , string $filename [, int $length = 0 ] )
如果操作成功,返回 true;如果失败,返回 false。
以下是一个示例,展示了如何使用 hash_update_file 来更新哈希值:
<?php
// 初始化哈希上下文,选择哈希算法
$context = hash_init('sha256');
<p>// 更新哈希值,读取文件进行哈希计算<br>
if (hash_update_file($context, 'example.txt')) {<br>
echo "文件哈希值更新成功!";<br>
} else {<br>
echo "文件哈希值更新失败!";<br>
}</p>
<p>// 获取最终的哈希值<br>
echo "文件的 SHA-256 哈希值为: " . hash_final($context);<br>
?><br>