md5_file()

md5_file() — Calculates the md5 hash of a given file.

Built-in function of PHP 8.5. The manual lists it as available in PHP 4 >= 4.2.0, PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.

What it does

Calculates the MD5 hash of the file specified by the filename parameter using the RSA Data Security, Inc. MD5 Message-Digest Algorithm, and returns that hash. The hash is a 32-character hexadecimal number.

Signature

md5_file(string $filename, bool $binary = false): string|false

Parameters

ParameterTypeWhat it takes
$filenamestringThe filename
$binaryboolWhen true, returns the digest in raw binary format with a length of 16.

Return value

Returns a string on success, false otherwise.

Example

A runnable snippet:

$file = '/examples/book.xml'; echo 'MD5 file hash of ' . $file . ': ' . md5_file($file);

See also

hash_file(), hash_init(), md5()

All PHP 8.5 built-in functions

Reference card built from the PHP manual page md5_file() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.