The md5_file() function is used to calculate the md5 hash of a given file. Let us first learn what is MD5 −
The MD5 message-digest algorithm takes as input a message of arbitrary length and produces as output a 128-bit "fingerprint" or "message digest" of the input. The MD5 algorithm is intended for digital signature applications, where a large file must be "compressed" in a secure manner before being encrypted with a private (secret) key under a public-key cryptosystem such as RSA.
-- Ref: From RFC 1321 - The MD5 Message-Digest Algorithm −
Syntax
md5_file(file_name, raw)
Parameters
file_name − Specifies the file for SHA1 hash
raw − Specify Boolean values −
TRUE - Raw 16 character binary format
FALSE - Default. 32 character hex number
Return
The md5_file() function returns a string on success, else FALSE.
Example
The following is an example −
<?php $file = "Md5.txt"; $md5file = md5_file($file); echo $md5file; ?>
Output
The following is the output −
1e5gbjhwbdk3enkjnd9bkjbw82kjbs