PHP Function Reference

PHP hash_update_file() Function



The PHP hash_update_file() function is used to pump data into an active hashing context from a file.

Syntax

hash_update_file(context, filename, stream_context)

Parameters

context Required. Specify hashing context returned by hash_init().
filename Required. Specify URL describing location of file to be hashed. It supports fopen wrappers.
stream_context Optional. Specify the stream context as returned by stream_context_create() function.

Return Value

Returns true on success or false on failure.

Example: hash_update_file() example

The example below shows the usage of hash_update_file() function.

<?php
//creating a file to calculate hash of
file_put_contents('test.txt', 'Hello World!');

//initializing an incremental hashing context
$ctx = hash_init('md5');

//updating context
hash_update_file($ctx, 'test.txt');

//finalizing an incremental hash
//and returning resulting digest
echo hash_final($ctx);
?>

The output of the above code will be:

ed076287532e86365e841e92bfc50d8c

❮ PHP Hash Reference