function filehash_hash in File Hash 8
Calculates the file hashes.
3 calls to filehash_hash()
- filehash_file_create in ./
filehash.module - Implements hook_ENTITY_TYPE_create().
- filehash_file_load in ./
filehash.module - Implements hook_ENTITY_TYPE_load().
- filehash_file_presave in ./
filehash.module - Implements hook_ENTITY_TYPE_presave().
File
- ./
filehash.module, line 147 - Generate hashes for each uploaded file.
Code
function filehash_hash($file) {
$file->filehash = array_fill_keys([
'md5',
'sha1',
'sha256',
], NULL);
// Unreadable files will have NULL hash values.
if (!is_readable($file
->getFileUri())) {
return;
}
foreach (filehash_algos() as $algo) {
$file->filehash[$algo] = hash_file($algo, $file
->getFileUri());
}
}