The md5_file() function in PHP 8.5 remains unchanged from previous versions. It calculates the MD5 hash of a file and returns it as a 32-character hexadecimal string.
Syntax
md5_file(string $filename, bool $binary = false): string|false
Parameters
- $filename: The path to the file you want to hash.
- $binary: (Optional) If set to true, the function returns the raw 16-byte binary digest instead of the 32-character hex string. Defaults to false.
Return Value
Returns the hash string on success, or false on failure (e.g., if the file cannot be read).
Example
$file = /path/to/your/file.txt ;
$hash = md5_file($file);if ($hash !== false) {
echo "MD5 hash of $file: $hash";
} else {
echo "Could not read the file.";
}