PHP - hash_update_file() 函式



定義和用法

hash_update_file() 函式將使用雜湊上下文更新給定檔案的內容。

語法

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

引數

序號 引數和描述
1

HashContext context

使用 hash_init() 獲取的雜湊上下文。

2

filename

要獲取其內容進行雜湊的檔案路徑。

3

scontext

由 stream_context_create() 返回的流上下文。

返回值

PHP hash_update_file() 函式返回一個布林值,即 true/false。

PHP 版本

此函式將在 PHP 5.1.2 或更高版本中執行。

示例 1

使用 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);
?>

輸出

這將產生以下結果 -

b10a8db164e0754105b7a99be72e3fe5

示例 2

使用 gost-crypto 演算法使用 hash_update_file() −

<?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);
?>

輸出

這將產生以下結果 -

75ed15d84df84291c67fe07bf234ac69e92a9c2a378ee62f342af739e829eba9
php_function_reference.htm
廣告