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 — Injeta dados em um contexto de hash ativo a partir de um fluxo
context
Contexto de hash retornado por hash_init().
stream
Identificador de arquivo aberto conforme retornado por qualquer função de criação de fluxo.
length
Número máximo de caracteres a serem copiados de stream
para o contexto de hash.
Número real de bytes adicionados ao contexto de hash de stream
.
Exemplo #1 Exemplo de 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);
?>
O exemplo acima produzirá:
68b1282b91de2c054c36629cb8dd447f12f096d3e3c587978dc2248444633483
This can be obvious, but hash_update_stream() move file pointer. So, use rewind(), if you plan to read the file after hashing.