= 5.1.2, PHP 7, PHP 8, PECL hash >= 1.1)hash_file — 給指定文件的內(nèi)容生成哈希值說明hash_file(string $algo, string $filename, bool $binary = false): s">
<pre id="5qwuk"><fieldset id="5qwuk"></fieldset></pre>
<dl id="5qwuk"><span id="5qwuk"><dfn id="5qwuk"></dfn></span></dl>
<pre id="5qwuk"><strike id="5qwuk"><delect id="5qwuk"></delect></strike></pre>
<nobr id="5qwuk"><menu id="5qwuk"></menu></nobr>
  • <thead id="5qwuk"></thead>

    hash_file

    (PHP 5 >= 5.1.2, PHP 7, PHP 8, PECL hash >= 1.1)

    hash_file給指定文件的內(nèi)容生成哈希值

    說明

    hash_file(string $algo, string $filename, bool $binary = false): string|false

    參數(shù)

    algo

    要使用的哈希算法的名稱(例如:"md5","sha256","haval160,4" 等)。 可以在 hash_algos() 中查看當(dāng)前支持的算法。

    filename

    要進(jìn)行哈希運算的文件位置的 URL ;支持 fopen 封裝協(xié)議。

    binary

    設(shè)置為 true 時,輸出原始二進(jìn)制數(shù)據(jù)。 設(shè)置為 false 時,輸出小寫的十六進(jìn)制字符串。

    返回值

    如果 binary 設(shè)置為 true, 則返回原始二進(jìn)制數(shù)據(jù)表示的信息摘要, 否則返回十六進(jìn)制小寫字符串格式表示的信息摘要。

    范例

    示例 #1 使用 hash_file()

    <?php
    /* 創(chuàng)建一個要計算哈希值的文件 */
    file_put_contents('example.txt''The quick brown fox jumped over the lazy dog.');
    echo 
    hash_file('md5''example.txt');
    ?>

    以上例程會輸出:

    5c6ffbdd40d9556b73a21e63c3e0e904
    

    參見

    • hash() - 生成哈希值 (消息摘要)
    • hash_hmac_file() - 使用 HMAC 方法和給定文件的內(nèi)容生成帶密鑰的哈希值
    • hash_update_file() - 從文件向活躍的哈希運算上下文中填充數(shù)據(jù)
    • md5_file() - 計算指定文件的 MD5 散列值
    • sha1_file() - 計算文件的 sha1 散列值