title: Validating files in Zend Framework 2
body: <p>Examine code below, I get file from upload and I want to validate it. I check file extensiton, size and MIME. If I check them one by one results are correct, but when I use $adapter->setValidators() result is false positive.  </p>
  
  <p>Are ZF2 validators act in weird way or maybe I don't understand how I am supposed to use it?</p>
  
  <h2>CODE</h2>
  
  <pre><code>&lt;?php    
      $data = array_merge_recursive(
          $this-&gt;getRequest()-&gt;getPost()-&gt;toArray(),          
          $this-&gt;getRequest()-&gt;getFiles()-&gt;toArray()
      );
  
      /* set mime on server side */
      $finfo = new \finfo(FILEINFO_MIME);             
      $mimeinfo = explode(';', $finfo-&gt;file($data['upload_image']['tmp_name']));
      $data['upload_image']['type'] = $mimeinfo[0];
  
      $adapter = new \Zend\File\Transfer\Adapter\Http(); 
  
      $validatorSize = new \Zend\Validator\File\Size(10);
      $validatorExt = new \Zend\Validator\File\Extension('gif,jpg,jpeg,png');
      $validatorMime = new \Zend\Validator\File\MimeType('image/gif,image/jpg,image/jpeg,image/png');
  
      $results = array();
      $results['size'] = $validatorSize-&gt;isValid($data['upload_image']);
      $results['ext'] = $validatorExt-&gt;isValid($data['upload_image']);
      $results['mime'] = $validatorMime-&gt;isValid($data['upload_image']);
  
      $adapter-&gt;setValidators(array(
          $validatorSize,
          $validatorExt,
          $validatorMime,
      ), $data['upload_image']);
  
      $results['adapter'] = $adapter-&gt;isValid();
  
      \Zend\Debug\Debug::dump($results);
  ?&gt;
  </code></pre>
  
  <h2>RESULTS</h2>
  
  <pre><code>array(4) {
    ["size"] =&gt; bool(false)
    ["ext"] =&gt; bool(true)
    ["mime"] =&gt; bool(false)
    ["adapter"] =&gt; bool(true)
  }
  </code></pre>