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

ExcludeMimeType Validator

The ExcludeMimeType validator checks the MIME type of transferred files. It supports the following options:

  • *: Sets any key individually or use a numeric array. Sets the MIME type to validate against.

    With this option you can define the MIME type of files that are not to be accepted.

  • headerCheck: If set to TRUE this option will check the HTTP Information for the file type when the fileInfo or mimeMagic extensions can not be found. The default value for this option is FALSE.

This validator accepts multiple MIME types, either as a comma-delimited string, or as an array. You may also use the methods setMimeType(), addMimeType(), and getMimeType() to set and retrieve the MIME types.

Example 414. Using the ExcludeMimeType Validator

= new Zend_File_Transfer();

// Does not allow MIME type of gif images for all files

// Does not allow MIME type of gif and jpg images for all given files
$upload->addValidator('ExcludeMimeType'false, array('image/gif',

// Does not allow MIME type of the group images for all given files

The above example shows that it is also possible to disallow groups of MIME types. For example, to disallow all images, just use 'image' as the MIME type. This can be used for all groups of MIME types like 'image', 'audio', 'video', 'text', etc.


Note that disallowing groups of MIME types will disallow all members of this group even if this is not intentional. When you disallow 'image' you will disallow all types of images like 'image/jpeg' or 'image/vasa'. When you are not sure if you want to disallow all types, you should disallow only specific MIME types instead of complete groups.

Zend Framework