A \Zend\Validator\File\Md5
, generally speaking, wouldn't be very useful in a webform.
Either the user has to provide the MD5 hash on a separate field, or you have to calculate it dynamically via javascript before the form is submitted. And on either case, you can't really use to "validate" the file, since you would either depend on the file to provide the validation hash, and it's useless to verify the upload completed (if the upload fails, the request will be aborted and you wont have access to the incomplete file).
You could probably use to validate some sort of server initiated download. E.g. somewhere in your code you've download a file, and somewhere separately you get access to the hash of the file you are going to download: you can then use \Zend\Validator\File\Md5
to validate the authenticity/integrity.
E.g.:
$file_path = '/downloads/file.tgz';
$fp = fopen ($file_path, 'w');
$url = "http://remotehost/file.tgz";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_TIMEOUT, 50);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$data = curl_exec($ch);
curl_close($ch);
// either you get the hash with a different request, or you've somehow obtained the hash previously
$validator = new \Zend\Validator\File\Md5($hash);
if (! $validator->isValid($file_path)) {
// file isn't valid, do something about it
}