• PHP Video Tutorials

PHP - hash update file() Function



Definition and Usage

The hash_update_file() function will update the given file content with the hash context.

Syntax

hash_update_file ( HashContext $hcontext , string $filename [, resource $scontext = NULL ] ) : bool

Parameters

Sr.No Parameter & Description
1

HashContext context

The hash context that you get using hash_init().

2

filename

The file path, to get the content to be hashed.

3

scontext

Stream context as returned by stream_context_create().

Return Values

PHP hash_update_file() function returns a boolean value i.e. true/false.

PHP Version

This function will work from PHP Version greater than 5.1.2.

Example 1

Using hash_update_file −

<?php
   $hash_context = hash_init('md5');
   file_put_contents('file1.txt', 'Hello World'); 
   // create file file1.txt with content : 'Hello World'
   hash_update_file($hash_context, 'file1.txt');
   echo hash_final($hash_context);
?>

Output

This will produce the following result −

b10a8db164e0754105b7a99be72e3fe5

Example 2

Using hash_update_file() with gost-crypto algorithm −

<?php
   $hash_context = hash_init('gost-crypto');
   file_put_contents('file1.txt', 'Hello World'); 
   // create file file1.txt with content : 'Hello World'
   hash_update_file($hash_context, 'file1.txt');
   echo hash_final($hash_context);
?>

Output

This will produce the following result −

75ed15d84df84291c67fe07bf234ac69e92a9c2a378ee62f342af739e829eba9
php_function_reference.htm
Advertisements