Oihana PHP

fileChecksum.php

Table of Contents

Functions

fileChecksum()  : string
Computes the checksum (hash) of a file's contents.

Functions

fileChecksum()

Computes the checksum (hash) of a file's contents.

fileChecksum(string $file[, string $algorithm = 'sha256' ]) : string

Reads the file through hash_file(), so the whole file does not need to be loaded into memory. Useful for integrity checks, deduplication, and verifying extracted archives.

Parameters
$file : string

Path to the file to hash.

$algorithm : string = 'sha256'

A hashing algorithm supported by hash_algos() (default: 'sha256').

Tags
throws
FileException

If the file is missing or unreadable, the algorithm is unsupported, or the hash computation fails.

author

Marc Alcaraz (ekameleon)

since
1.2.0
example
use function oihana\files\fileChecksum;

$sha256 = fileChecksum( '/data/report.pdf' ) ;            // default sha256
$md5    = fileChecksum( '/data/report.pdf' , 'md5' ) ;    // explicit algorithm
Return values
string

The computed hash, lowercase hexadecimal.

On this page

Search results