php函數:md5_file()函數執行個體教程

來源:互聯網
上載者:User

定義和用法
該md5_file ( )Function ComputeMD5雜湊的檔案。

該md5_file ( )函數使用的RSA資料安全公司的MD5訊息摘要演算法。

從1321年的RFC -的M D5訊息摘要演算法: “的M D5訊息摘要演算法需要輸入的資訊任意長度和生產輸出了1 28位”指紋“或”訊息摘要“的投入。的M D5演算法打算用於數位簽章的應用,其中一個大檔案必須是“壓縮”在一個安全的方式加密之前,與一家私營(秘密)主要根據公開金鑰密碼體制,如RSA的。 “

這個函數返回計算MD5雜湊成功,或FALSE的失敗。

文法

md5_file(file,raw)
  
Parameter Description
file Required. The file to be calculated
raw
任擇。指定十六進位或二進位輸出格式:真-原1 6個字元二進位格式假-預設。 32字元的十六進位數註:此參數是說在PHP 5.0
來看看執行個體.
<?php$filename = "test.txt";$md5file = md5_file($filename);echo $md5file;?>
輸出為.
5d41402abc4b2a76b9719d911017c592
 
下面來看個邏輯的執行個體.
 
<?php$md5file = md5_file("test.txt");file_put_contents("md5file.txt",$md5file);?>
    

在這個例子中,我們將測試是否“ test.txt ”已變更(即如果MD5雜湊已變更) :

 

<?php$md5file = file_get_contents("md5file.txt");if (md5_file("test.txt") == $md5file)  {  echo "The file is ok.";  }else  {  echo "The file has been changed.";  }?>
輸出.
 
The file is ok

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.