This can be obvious, but hash_update_stream() move file pointer. So, use rewind(), if you plan to read the file after hashing.
(PHP 5 >= 5.1.2, PHP 7, PHP 8, PECL hash >= 1.1)
hash_update_stream — アクティブなハッシュコンテキストに、オープンしているストリームから データを投入する
context
hash_init() が返すハッシュコンテキスト。
stream
ストリーム作成用の関数が返す、オープンしているファイルハンドル。
length
stream
からハッシュコンテキストにコピーする
最大文字数。
stream
からハッシュコンテキストに追加された
実際のバイト数を返します。
例1 hash_update_stream() の例
<?php
$fp = tmpfile();
fwrite($fp, 'jumped over the lazy dog.');
rewind($fp);
$ctx = hash_init('sha256');
hash_update($ctx, 'The quick brown fox ');
hash_update_stream($ctx, $fp);
echo hash_final($ctx);
?>
上の例の出力は以下となります。
68b1282b91de2c054c36629cb8dd447f12f096d3e3c587978dc2248444633483
This can be obvious, but hash_update_stream() move file pointer. So, use rewind(), if you plan to read the file after hashing.
Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!
Check out: eBank.nz (Art Generator) |
Netwrck.com (AI Tools) |
Text-Generator.io (AI API) |
BitBank.nz (Crypto AI) |
ReadingTime (Kids Reading) |
RewordGame |
BigMultiplayerChess |
WebFiddle |
How.nz |
Helix AI Assistant