hash_file
Description
Syntax
hash_file( string $algo, string $filename, bool $binary = false, array $options = [] ): string|false
Parameters
algo
Name of selected hashing algorithm.
filename
The filename of the file to hash.
binary
When set to true, outputs raw binary data. false outputs lowercase hexits.
options
An array of options for the various hashing algorithms. Currently, only the "seed" parameter is supported by the MurmurHash variants.
Return
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.
Examples
1 · algo filename
<? $algo = 'sha384'; $filename = $_SERVER['DOCUMENT_ROOT'] . '/assets/txt/1.txt'; $return = hash_file($algo, $filename); echo $return; ?>
59e1748777448c69de6b800d7a33bbfb9ff1b463e44354c3553bcdb9c666fa90125a3c79f90397bdf5f6a13de828684f
2 · binary
<? $algo = 'sha384'; $filename = $_SERVER['DOCUMENT_ROOT'] . '/assets/txt/1.txt'; $binary = true; $return = hash_file($algo, $filename, $binary); echo $return . PHP_EOL . bin2hex($return); ?>
Y�t�wD�i�k� z3����c�CT�U;�f��Z<y������=�(hO 59e1748777448c69de6b800d7a33bbfb9ff1b463e44354c3553bcdb9c666fa90125a3c79f90397bdf5f6a13de828684f
3 · options · empty
<? $algo = 'sha384'; $filename = $_SERVER['DOCUMENT_ROOT'] . '/assets/txt/1.txt'; $binary = false; $options = []; $return = hash_file($algo, $filename, $binary, $options); echo $return; ?>
59e1748777448c69de6b800d7a33bbfb9ff1b463e44354c3553bcdb9c666fa90125a3c79f90397bdf5f6a13de828684f
4 · options · seed
<? $algo = 'murmur3f'; $filename = $_SERVER['DOCUMENT_ROOT'] . '/assets/txt/1.txt'; $binary = false; $options = ['seed' => 42]; $return = hash_file($algo, $filename, $binary, $options); echo $return; ?>
c4b8b3c960af6f082334b875b0efbc7a