hash_file
Function • Params changed in PHP 8.1
Generate a hash value using the contents of a given file.
hash_file Function synopsis
hash_file(
string $algo,
string $filename,
bool $binary = false,
array $options = []
): string|false
Parameters
$algo
Typestring
Name of selected hashing algorithm (e.g. "sha256").
For a list of supported algorithms see hash_algos.
$filename
Typestring
URL describing location of file to be hashed; Supports fopen wrappers.
$binary
OptionalTypeboolDefault valuefalse
When set to true, outputs raw binary data.
false outputs lowercase hexits.
$options
OptionalTypearrayDefault value[]
An array of options for the various hashing algorithms.
Currently, only the "seed" parameter is
supported by the MurmurHash variants.
Return value
Typestring|false
Returns a string containing the calculated message digest as lowercase hexits
unless $binary is set to true in which case the raw
binary representation of the message digest is returned, or false on failure.
Changes to the hash_file Function
PHP 8.1
- Optional parameter added - #4:
array $options = []
hash_file(
string $algo,
string $filename,
- bool $binary = false
+ bool $binary = false,
+ array $options = []
): string|false PHP 8.0
- Return type added:
string|false - Parameter type added for parameter #1 (
$algo):string - Parameter type added for parameter #2 (
$filename):string - Parameter name of parameter #3 changed:
$raw_outputto$binary - Parameter type added for parameter #3 (
$binary):bool - Parameter default value added for position #3 (
$binary):false
hash_file(
- $algo,
+ string $algo,
- $filename,
+ string $filename,
- $raw_output
+ bool $binary = false
- )
+ ): string|false hash_file Function Availability
hash_file Function Availability| PHP Version | Availability |
|---|---|
| PHP 8.6Upcoming Release | Yes |
| PHP 8.5Supported (Latest) | Yes |
| PHP 8.4Supported | Yes |
| PHP 8.3Security-Fixes Only | Yes |
| PHP 8.2Security-Fixes Only | Yes |
| PHP 8.1Unsupported | Yes |
| PHP 8.0Unsupported | Yes |
| PHP 7.4Unsupported | Yes |
| PHP 7.3Unsupported | Yes |
| PHP 7.2Unsupported | Yes |
| PHP 7.1Unsupported | Yes |
| PHP 7.0Unsupported | Yes |
| PHP 5.6Unsupported | Yes |
| PHP 5.5Unsupported | Yes |
| PHP 5.4Unsupported | Yes |
| PHP 5.3Unsupported | Yes |