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
TRUEwhich 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
setMax() to set both
options after construction, along with
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 413. Using the Size Validator
$upload = new Zend_File_Transfer();
// Limit the size of a file to 40000 bytes
$upload->addValidator('Size', false, 40000);
// 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
array('min' => '10kB',
'max' => '4MB',
'bytestring' => false));