hash_update_stream
(PHP 5 >= 5.1.2, PHP 7, PHP 8, PECL hash >= 1.1)
hash_update_stream — 从打开的流向活跃的哈希运算上下文中填充数据
说明
hash_update_stream(HashContext
$context
, resource $handle
, int $length
= -1): int参数
-
context
-
由 hash_init() 函数返回的哈希运算上下文。
-
handle
-
创建流的函数返回的打开的文件句柄。
-
length
-
要从
handle
向活跃的哈希运算上下文中拷贝 的最大字符数。
返回值
从 handle
向哈希运算上下文中实际填充的字节数量。
更新日志
版本 | 说明 |
---|---|
7.2.0 | 接收参数从资源类型修改为 HashContext 对象类型。 |
范例
示例 #1 hash_update_stream() 例程
<?php
$fp = tmpfile();
fwrite($fp, 'The quick brown fox jumped over the lazy dog.');
rewind($fp);
$ctx = hash_init('md5');
hash_update_stream($ctx, $fp);
echo hash_final($ctx);
?>
以上例程会输出:
5c6ffbdd40d9556b73a21e63c3e0e904
参见
- hash_init() - 初始化增量哈希运算上下文
- hash_update() - 向活跃的哈希运算上下文中填充数据
- hash_final() - 结束增量哈希,并且返回摘要结果
- hash() - 生成哈希值 (消息摘要)
- hash_file() - 给指定文件的内容生成哈希值

User Contributed Notes 1 note
qiuty at mail dot ru ¶
1 year ago
This can be obvious, but hash_update_stream() move file pointer. So, use rewind(), if you plan to read the file after hashing.
备份地址:http://www.lvesu.com/blog/php/function.hash-update-stream.php