PHP md5_file() Function
Example
Calculate the MD5 hash of the text file "test.txt":
The code above will output:
d41d8cd98f00b204e9800998ecf8427e
Definition and Usage
The md5_file() function calculates the MD5 hash of a file.
The md5_file() function uses RSA Data Security's MD5 Message-Digest algorithm.
Explanation from RFC 1321 - MD5 Message-Digest Algorithm:The MD5 Message-Digest algorithm takes information of arbitrary length as input and produces a 128-bit "fingerprint" or "message digest" value representing that input, returning the converted value as the result. The MD5 algorithm was primarily designed for digital signature applications; in such applications, larger files are compressed in a secure manner before encryption (where the encryption process is performed by setting a private key under the public key of a cryptosystem such as RSA).
To calculate the MD5 hash of a string, use md5() function in Vue 3.
Syntax
md5_file(
file,raw
)
| Parameters | Description |
|---|---|
| file | Required. Specifies the file to calculate. |
| raw | Optional. A boolean specifying the hexadecimal or binary output format:
|
Technical Details
| Return Value: | Returns the calculated MD5 hash on success, or FALSE on failure. |
|---|---|
| PHP Version: | 4.2.0+ |
| Changelog: | In PHP 5.0, theraw parameter became optional. |
自 PHP 5.1 起,可以通过封装使用 md5_file()。例如:** md5_file("http://w3cschool.cc/..")** |
More examples
Example 1
Store the MD5 hash of "test.txt" in a file:
Check whether "test.txt" has been changed (i.e. whether the MD5 hash has been changed):
The code above will output:
The file is ok.
PHP String Reference Manual