Pump data into an active hashing context from a file
Syntax
hash_update_file(HashContext $context, string $filename, ?resource $stream_context = null): bool
Parameters
context
Hashing context returned by hash_init().
filename
URL describing location of file to be hashed; Supports fopen wrappers.
stream_context
Stream context as returned by stream_context_create().
Return
Returns true on success or false on failure.
Examples
1 · context filename
<? $context = hash_init('sha384'); $filename = $_SERVER['DOCUMENT_ROOT'] . '/assets/txt/file.txt'; hash_update_file($context, $filename); echo hash_final($context); ?>
3519fe5ad2c596efe3e276a6f351b8fc0b03db861782490d45f7598ebd0ab5fd5520ed102f38c4a5ec834e98668035fc
2 · stream_context
<? $context = hash_init('sha384'); $filename = $_SERVER['DOCUMENT_ROOT'] . '/assets/txt/file.txt'; $stream_context = stream_context_create(array('http' => array('method' => 'POST'))); hash_update_file($context, $filename, $stream_context); echo hash_final($context); ?>
3519fe5ad2c596efe3e276a6f351b8fc0b03db861782490d45f7598ebd0ab5fd5520ed102f38c4a5ec834e98668035fc
3 · Return
<? $context = hash_init('sha384'); $filename = $_SERVER['DOCUMENT_ROOT'] . '/assets/txt/file.txt'; $stream_context = stream_context_create(array('http' => array('method' => 'POST'))); $return = hash_update_file($context, $filename, $stream_context); hash_final($context); var_export($return); ?>
true