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

Size Validator

The Size validator checks for the size of a single file. It supports the following options:

  • min: Sets the minimum file size.

  • max: Sets the maximum file size.

  • bytestring: Defines whether a failure is returned with a user-friendly number, or with the plain file size.

    With this option you can define if the user gets '10864' or '10MB'. Default value is TRUE which returns '10MB'.

You can initialize this validator with a string, which will then be used to set the max option. You can also use the methods setMin() and setMax() to set both options after construction, along with getMin() and getMax() to retrieve the values that have been set previously.

The size itself is also accepted in SI notation as handled by most operating systems. That is, instead of specifying 20000 bytes, 20kB may be given. All file sizes are converted using 1024 as the base value. The following Units are accepted: kB, MB, GB, TB, PB and EB. Note that 1kB is equal to 1024 bytes, 1MB is equal to 1024kB, and so on.

Example 426. Using the Size Validator

= new Zend_File_Transfer();

// Limit the size of a file to 40000 bytes

// Limit the size a given file to maximum 4MB and mimimum 10kB
// Also returns the plain number in case of an error
// instead of a user-friendly number
'min' => '10kB',
'max' => '4MB',
'bytestring' => false));

Zend Framework