<?php
function hashFile(string $path, string $algo = 'sha256'): string {
$ctx = hash_init($algo);
$fh = fopen($path, 'rb');
if (!$fh) throw new RuntimeException("Cannot open $path");
try {
hash_update_stream($ctx, $fh); // streams in chunks internally
} finally {
fclose($fh);
}
return hash_final($ctx);
}
echo hashFile('/var/log/big.log'); // 64-char hex SHA-256
echo hashFile('/backup/db.dump.gz', 'sha512'); // 128-char hex SHA-512
Create a free account and build your private vault. Share publicly whenever you want.