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