array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'zh', ), 'this' => array ( 0 => 'function.hash-file.php', 1 => 'hash_file', ), 'up' => array ( 0 => 'ref.hash.php', 1 => 'Hash 函数', ), 'prev' => array ( 0 => 'function.hash-equals.php', 1 => 'hash_equals', ), 'next' => array ( 0 => 'function.hash-final.php', 1 => 'hash_final', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'zh', 'path' => 'reference/hash/functions/hash-file.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 5 >= 5.1.2, PHP 7, PHP 8, PECL hash >= 1.1)
hash_file — 给指定文件的内容生成散列值
algo
要使用的散列算法的名称(例如:“md5”、“sha256”、“haval160,4”等)。 可以在 hash_algos() 中查看当前支持的算法。
filename
要进行散列运算的文件位置的 URL;支持 fopen 封装协议。
binary
options
各种散列算法的一系列选项数组。目前 MurmurHash 算法仅支持 “seed” 参数。
如果 binary
设置为 true, 则返回原始二进制数据表示的信息摘要,
否则返回十六进制小写字符串格式表示的信息摘要。
版本 | 说明 |
---|---|
8.1.0 | 新增 options 参数。 |
示例 #1 hash_file() 示例
<?php
/* Create a file to calculate hash of */
file_put_contents('example.txt', 'The quick brown fox jumped over the lazy dog.');
echo hash_file('sha256', 'example.txt');
?>
以上示例会输出:
68b1282b91de2c054c36629cb8dd447f12f096d3e3c587978dc2248444633483