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

ExcludeExtension Validator

The ExcludeExtension validator checks the file extension of the specified files. It supports the following options:

  • *: Sets any key or use a numeric array. The values will be used to check whether the given file does not use this file extension.

  • case: Sets a boolean indicating whether validation should be case-sensitive. The default is not case sensitive. Note that this key can be applied to for all available extensions.

This validator accepts multiple extensions, either as a comma-delimited string, or as an array. You may also use the methods setExtension(), addExtension(), and getExtension() to set and retrieve extensions.

In some cases it is useful to match in a case-sensitive fashion. So the constructor allows a second parameter called $case which, if set to TRUE, validates the extension by comparing it with the specified values in a case-sensitive fashion.

Example 413. Using the ExcludeExtension Validator

= new Zend_File_Transfer();

// Do not allow files with extension php or exe

// Do not allow files with extension php or exe, but use array notation
$upload->addValidator('ExcludeExtension'false, array('php''exe'));

// Check in a case-sensitive fashion
'php''exe''case' => true));
'php''exe''case' => true));


Note that this validator only checks the file extension. It does not check the file's MIME type.

Zend Framework