PHP hash_update_stream() Function
The PHP hash_update_stream() function is used to pump data into an active hashing context from an open stream.
Syntax
hash_update_stream(context, stream, length)
Parameters
context |
Required. Specify hashing context returned by hash_init(). |
stream |
Required. Specify an open file handle as returned by any stream creation function. |
length |
Optional. Specify the maximum number of characters to copy from stream into the hashing context. |
Return Value
Returns the actual number of bytes added to the hashing context from stream.
Example: hash_update_stream() example
The example below shows the usage of hash_update_stream() function.
<?php //creating a temporary file $fp = tmpfile(); //write some content to it fwrite($fp, 'Hello World!'); //setting the file pointer to the start rewind($fp); //initializing an incremental hashing context $ctx = hash_init('md5'); //updating context hash_update_stream($ctx, $fp); //finalizing an incremental hash //and returning resulting digest echo hash_final($ctx); //closing the file fclose($fp); ?>
The output of the above code will be:
ed076287532e86365e841e92bfc50d8c
❮ PHP Hash Reference