HomeMenu
Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

sha1_file

Description

The sha1_file of String for PHP calculate the sha1 hash of a file.

Syntax

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

Parameters

filename

The filename of the file to hash.

binary

When true, returns the digest in raw binary format with a length of 20.

Return

Returns a string on success, false otherwise.

Examples

1 · filename

<?

$filename = $_SERVER['DOCUMENT_ROOT'] . '/assets/txt/1.txt';

$return = sha1_file($filename);

echo $return;
aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d

2 · binary

<?

$filename = $_SERVER['DOCUMENT_ROOT'] . '/assets/txt/1.txt';
$binary = true;

$return = sha1_file($filename, $binary);

echo $return . PHP_EOL;

$format = 'H*';

$unpack = unpack($format, $return);

$array_pop = array_pop($unpack);

echo $array_pop;
������ھ�;H,ٮ�CM
aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d