hash_update_file
Description
The hash_update_file of Hash for PHP 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
<? $algo = "sha384"; $context = hash_init($algo); $filename = $_SERVER['DOCUMENT_ROOT'] . "/assets/txt/1.txt"; hash_update_file($context, $filename); $hash = hash_final($context); echo $hash;
59e1748777448c69de6b800d7a33bbfb9ff1b463e44354c3553bcdb9c666fa90125a3c79f90397bdf5f6a13de828684f
2 · stream_context
<? $algo = "sha384"; $options = [ "http" => [ "method" => "POST" ] ]; $context = hash_init($algo); $filename = $_SERVER['DOCUMENT_ROOT'] . "/assets/txt/1.txt"; $stream_context = stream_context_create($options); hash_update_file($context, $filename, $stream_context); $hash = hash_final($context); echo $hash;
59e1748777448c69de6b800d7a33bbfb9ff1b463e44354c3553bcdb9c666fa90125a3c79f90397bdf5f6a13de828684f
3 · return
<? $algo = "sha384"; $options = [ "http" => [ "method" => "POST" ] ]; $context = hash_init($algo); $filename = $_SERVER['DOCUMENT_ROOT'] . "/assets/txt/1.txt"; $stream_context = stream_context_create($options); $return = hash_update_file($context, $filename, $stream_context); hash_final($context); var_export($return);
true