Php function: md5_file () function example tutorial

Source: Internet
Author: User

Definition and usage
The md5_file () function calculates the MD5 hash file.

The md5_file () function uses the MD5 message digest algorithm of the RSA Data Security Company.

The M D5 message digest algorithm from RFC 1321: "The M D5 message digest algorithm requires the input of any length of information and the output of a 28-bit fingerprint or message digest input. The M D5 algorithm is intended to be used for digital signature applications. One of the large files must be "compressed". Before a secure encryption method is used, a private (secret) algorithm is primarily used in accordance with the public key cryptography system, such as RSA. "

This function returns MD5 hash calculation success, or FALSE failure.

Syntax

Md5_file (file, raw)
  
Parameter Description
File Required. The file to be calculated
Raw
Optional. Specify the hexadecimal or binary output format: True-original 1 6 character binary format false-default. 32-character hexadecimal number. Note: this parameter is used in PHP 5.0.
To see the instance.
<? Php $ filename = "test.txt"; $ md5file = md5_file ($ filename); echo $ md5file;?>
Output is.
5d41402abc4b2a76b9719d911017c592
 
Here is a logical instance.
 
<? Php $ md5file = md5_file ("test.txt"); file_put_contents ("md5file.txt", $ md5file);?>
    

In this example, we will test whether "test.txt" has been changed (that is, if the MD5 hash has been changed ):

 

<? 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. ";}?>
Output.
 
The file is OK

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.