Instance
Computes the MD5 hash of the text file "Test.txt":
<?php$filename = "Test.txt"; $md 5file = Md5_file ($filename); Echo $md 5file;? >
The above code will output:
d41d8cd98f00b204e9800998ecf8427e
Definition and usage
The Md5_file () function computes the MD5 hash of the file.
The Md5_file () function uses RSA data security, including MD5 Digest to algorithm.
Explanation from RFC 1321-MD5 Digest to algorithm: MD5 Digest to the algorithm will be arbitrary length of information as input value, and convert it into a 128-bit length of "fingerprint Information" or "Digest to" value to represent this input value, and with the converted value as the result. The MD5 algorithm is designed primarily for digitally signed applications, where large files are compressed in a secure manner prior to encryption (where encryption is done by setting a private key under the public key of a cryptographic system, such as RSA).
To calculate the MD5 hash of a string, use the MD5 () function.
Grammar
Md5_file (File,raw)
Parameter description
File required. Specify the documents to be calculated.
Raw is optional. A Boolean value that specifies the hexadecimal or binary output format:
TRUE-Original 16 character binary format
FALSE-Default. 32-character hexadecimal number
Technical details
Return value: Returns the computed MD5 hash if successful, or FALSE if it fails.
PHP version: 4.2.0+
Update log: In PHP 5.0, the raw parameter becomes optional.
From PHP 5.1, md5_file () can be used through encapsulation. Example: Md5_file ("http://w3cschool.cc/..")
More examples
Example 1
Store the MD5 hash of "test.txt" in the file:
<?php$md5file = Md5_file ("test.txt"); File_put_contents ("Md5file.txt", $md 5file);? >
Detects if "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") = = $md 5file) {echo "The file is OK."} Else{echo "The file has been changed.";}? >
The above code will output:
The file is OK.