Zend\Validator\File\Hash allows you to validate if a given file’s hashed contents matches the supplied hash(es) and algorithm(s).
Note
This validator requires the Hash extension from PHP. A list of supported hash algorithms can be found with the hash_algos() function.
Supported Options
The following set of options are supported:
Hash to test the file against.
Algorithm to use for the hashing validation.
Usage Examples
1 2 3 4 5 6 7 8 9 10 | // Does file have the given hash?
$validator = new \Zend\Validator\File\Hash('3b3652f', 'crc32');
// Or, check file against multiple hashes
$validator = new \Zend\Validator\File\Hash(array('3b3652f', 'e612b69'), 'crc32');
// Perform validation with file path
if ($validator->isValid('./myfile.txt')) {
// file is valid
}
|
Public Methods
Returns the current set of hashes.
Return type: | array |
---|
Adds a hash for one or multiple files to the internal set of hashes.
Parameters: | $options – See Supported Options section for more information. |
---|
Sets a hash for one or multiple files. Removes any previously set hashes.
Parameters: | $options – See Supported Options section for more information. |
---|
The source code of this file is hosted on GitHub. Everyone can update and fix errors in this document with few clicks - no downloads needed.