Zend\Validator\File\Md5 allows you to validate if a given file’s hashed contents matches the supplied md5 hash(es). It is subclassed from the Hash validator to provide a convenient validator that only supports the md5 algorithm.


This validator requires the Hash extension from PHP with the md5 algorithm.

Supported Options

The following set of options are supported:

  • hash (string)

    Hash to test the file against.

Usage Examples

// Does file have the given hash?
$validator = new \Zend\Validator\File\Md5('3b3652f336522365223');

// Or, check file against multiple hashes
$validator = new \Zend\Validator\File\Md5(array(
    '3b3652f336522365223', 'eb3365f3365ddc65365'

// Perform validation with file path
if ($validator->isValid('./myfile.txt')) {
    // file is valid

Public Methods


Returns the current set of md5 hashes.

Return type:array
addMd5(string|array $options)

Adds a md5 hash for one or multiple files to the internal set of hashes.

Parameters:$options – See Supported Options section for more information.
setMd5(string|array $options)

Sets a md5 hash for one or multiple files. Removes any previously set hashes.

Parameters:$options – See Supported Options section for more information.

Table Of Contents

This Page

Note: You need to stay logged into your GitHub account to contribute to the documentation.

Edit this document

Edit this document

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.

  1. Login with your GitHub account.
  2. Go to Md5 on GitHub.
  3. Edit file contents using GitHub's text editor in your web browser
  4. Fill in the Commit message text box at the end of the page telling why you did the changes. Press Propose file change button next to it when done.
  5. On Send a pull request page you don't need to fill in text anymore. Just press Send pull request button.
  6. Your changes are now queued for review under project's Pull requests tab on GitHub.