Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...

When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store

Hash Validator

The Hash validator checks the content of a transferred file by hashing it. This validator uses the hash extension from PHP. It supports the following options:

  • *: Takes any key or use a numeric array. Sets the hash to validate against.

    You can set multiple hashes by passing them as an array. Each file is checked, and the validation will fail only if all files fail validation.

  • algorithm: Sets the algorithm to use for hashing the content.

    You can set multiple algorithm by calling the addHash() method multiple times.

Example 421. Using the Hash Validator

= new Zend_File_Transfer();

// Checks if the content of the uploaded file contains the given hash

// Limits this validator to two different hashes
$upload->addValidator('Hash'false, array('3b3652f''e612b69'));

// Sets a different algorithm to check against
'algorithm' => 'md5'));


This validator supports about 34 different hash algorithms. The most common include 'crc32', 'md5' and 'sha1'. A comprehesive list of supports hash algorithms can be found at the hash_algos method on the site.

Zend Framework