sha1_file()
sha1_file() — Calculate the sha1 hash of a file.
Built-in function of PHP 8.5. The manual lists it as available in PHP 4 >= 4.3.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 sha1 hash of the file specified by filename using the US Secure Hash Algorithm 1, and returns that hash. The hash is a 40-character hexadecimal number.
Signature
sha1_file(string $filename, bool $binary = false): string|false
Parameters
| Parameter | Type | What it takes |
|---|---|---|
| $filename | string | The filename of the file to hash. |
| $binary | bool | When true, returns the digest in raw binary format with a length of 20. |
Return value
Returns a string on success, false otherwise.
Example
A runnable snippet:
foreach (glob('/examples/*.xml') as $ent) { if (is_dir($ent)) { continue; } echo $ent . ' (SHA1: ' . sha1_file($ent) . ')', PHP_EOL; }
See also
hash_file(), hash_init(), sha1()
All PHP 8.5 built-in functions
Reference card built from the PHP manual page sha1_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.