Zend\Validator\File\MimeType raises a warning if no file was uploaded #5105

liorch88 opened this Issue Sep 12, 2013 · 3 comments


None yet

3 participants


When I am using the Zend\Validator\File\MimeType validator (actually, the IsImage validator) on a form, if no file was uploaded - it will raise the following warning:

Warning: finfo_file(): Empty filename or path in \vendor\zendframework\zendframework\library\Zend\Validator\File\MimeType.php on line 392

The file field is created using the following annotation:

     * @Annotation\Type("Zend\Form\Element\File")
     * @Annotation\Attributes({"accept":"image/*"})
     * @Annotation\Required({"required":"true"})
     * @Annotation\Validator({"name": "File\UploadFile"})
     * @Annotation\Validator({"name": "File\IsImage"})
     * @Annotation\Options({"label":"Image:"})
    protected $image;

And the form was created in the way the manual suggests:

// Merge post and file info
 $post = array_merge_recursive(


if ($form->isValid()) {

@liorch88 you are doing it general right.

In my code (multiple upload enabled), i check for an empty file name an skip it.

Can u check if this "hack" would solve your problem? I think the problem have to fixed elsewhere and not in the MimeType....

            $post = array_merge_recursive($request->getPost()->toArray(), $request->getFiles()->toArray());
            if ($form->isValid() === true) {
                $files = $request->getFiles()->toArray();

                $imageFiles = $files['images'];
                foreach ($imageFiles as $imageFile) {
                    if ($imageFile['name'] == '') {

                    //ok...do something with the file
liorch88 commented Nov 1, 2013

I believe the validator itself should be able to handle something as common as a missing file - because it is a very common situation that a user simply did not upload a file.

I think the solution should be in MimeType. Before running the actual mimetype checks, it should see that the $file is ok. Maybe just before the first check (the "is file name readable? check), around line 370, to add something like:

// File name not empty?
if (empty($file)) {
    return false;

The other reason for doing so in the validator itself, and not on the user side - is that I believe that the framework itself should never cause an "uncaught" error or warning - it should try and handle all the php errors itself (as it does using the ErrorHandler..)

@GeeH GeeH added the To Be Closed label Mar 5, 2016
GeeH commented Jun 27, 2016

This issue has been closed as part of the bug migration program as outlined here - http://framework.zend.com/blog/2016-04-11-issue-closures.html

@GeeH GeeH closed this Jun 27, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment