PHP 字符串 md5_file() 函數是內置的重要函數。它用於計算文件的 MD5 哈希值。它使用 RSA 數據安全。成功時返回 md5 哈希,失敗時返回 FALSE。
用法:
md5_file(file,raw);
參數 | 描述 | 必需/可選 |
---|---|---|
File | 指定要計算的文件。 | Required |
Raw | 指定布爾十六進製或二進製格式。
|
Optional |
例子1
保存它:"test.txt" 文件並將其粘貼到文件中的 "Hello PHP" 字符串中。
<?php
$filename = "test.txt";
$md5file = md5_file($filename);
echo $md5file;
?>
輸出:
c540ce201d398a7d275c6e0c669097f3
例子2
我們可以將 "test.txt" 的 MD5 哈希存儲在一個文件中:
<?php
$file = md5_file("test.txt");
file_put_contents("md5file.txt",$file);
?>
我們可以測試 "test.txt" 是否發生了變化(如果 MD5 哈希值發生了變化):
<?php
$file = file_get_contents("md5file.txt");
if (md5_file("test.txt") == $file){
echo "The file is ok.";
}
else{
echo "The file has been changed.";
}
?>
輸出:
The file is ok.
相關用法
- PHP string md5()用法及代碼示例
- PHP string money_format()用法及代碼示例
- PHP string rtrim()用法及代碼示例
- PHP string printf()用法及代碼示例
- PHP string ord()用法及代碼示例
- PHP string join()用法及代碼示例
- PHP string sha1()用法及代碼示例
- PHP string setlocale()用法及代碼示例
- PHP string sha1_file()用法及代碼示例
- PHP string ltrim()用法及代碼示例
- PHP string str_repeat()用法及代碼示例
- PHP string lcfirst()用法及代碼示例
- PHP string str_shuffle()用法及代碼示例
- PHP string similar_text()用法及代碼示例
- PHP string crypt()用法及代碼示例
- PHP string str_ireplace()用法及代碼示例
- PHP string str_split()用法及代碼示例
- PHP string strcoll()用法及代碼示例
- PHP string str_rot13()用法及代碼示例
注:本文由純淨天空篩選整理自 PHP string md5_file() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。