Easy Tutorial
❮ Func Array Usort Php Password_Needs_Rehash ❯

PHP md5_file() Function

PHP String Reference Manual

Example

Calculate the MD5 hash of the text file "test.txt":

The above code will output:


Definition and Usage

The md5_file() function calculates the MD5 hash of a file.

The md5_file() function uses the RSA Data Security, including the MD5 Message-Digest Algorithm.

Explanation from RFC 1321 - MD5 Message-Digest Algorithm: The MD5 Message-Digest Algorithm takes an input and converts it into a 128-bit fingerprint or "message digest" that represents the input. The algorithm is primarily designed for digital signature applications; in these applications, larger files are securely compressed before being encrypted (the encryption process is done by setting a private key under a public key in a cryptographic system, such as RSA).

To calculate the MD5 hash of a string, use the md5() function.


Syntax

Parameter Description
file Required. Specifies the file to calculate.
raw Optional. A boolean value that specifies hexadecimal or binary output format: TRUE - Raw 16-character binary format<br> FALSE - Default. 32-character hexadecimal number

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, the raw parameter became optional. <br> <br>Since PHP 5.1, md5_file() can be used with wrappers. For example: md5_file("http://w3cschool.cc/..")
--- ---

More Examples

Example 1

Store the MD5 hash of "test.txt" in a file:

Check if "test.txt" has been altered (i.e., if the MD5 hash has changed):

The above code will output:


❮ Func Array Usort Php Password_Needs_Rehash ❯