(PHP 5 >= 5.1.2, PHP 7, PHP 8, PECL hash >= 1.1)
hash_file — 給指定文件的內容生成哈希值
$algo
, string $filename
, bool $binary
= false
): string|false
algo
要使用的哈希算法的名稱(chēng)(例如:"md5","sha256","haval160,4" 等)。 可以在 hash_algos() 中查看當前支持的算法。
filename
要進(jìn)行哈希運算的文件位置的 URL ;支持 fopen 封裝協(xié)議。
binary
設置為 true
時(shí),輸出原始二進(jìn)制數據。
設置為 false
時(shí),輸出小寫(xiě)的十六進(jìn)制字符串。
如果 binary
設置為 true, 則返回原始二進(jìn)制數據表示的信息摘要,
否則返回十六進(jìn)制小寫(xiě)字符串格式表示的信息摘要。
示例 #1 使用 hash_file()
<?php
/* 創(chuàng )建一個(gè)要計算哈希值的文件 */
file_put_contents('example.txt', 'The quick brown fox jumped over the lazy dog.');
echo hash_file('md5', 'example.txt');
?>
以上例程會(huì )輸出:
5c6ffbdd40d9556b73a21e63c3e0e904