close
[php]sha1_file() 函數計算文件的 SHA-1 散列
例子 1
<?php
$filename = "test.txt";
$sha1file = sha1_file($filename);
echo $sha1file;
?>
輸出:
aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d
例子 2
在一個文件中存儲 "test.txt" 的 SHA-1 散列:
<?php
$sha1file = sha1_file("test.txt");
file_put_contents("sha1file.txt",$sha1file);
?>
在本例中,我們將測試 "test.txt" 是否已更改(即 SHA-1 hash 是否已更改):
<?php
$sha1file = file_get_contents("sha1file.txt");
if (sha1_file("test.txt") == $sha1file)
{
echo "The file is ok.";
}
else
{
echo "The file has been changed.";
}
?>
輸出:
The file is ok.
全站熱搜