The FilesSize validator checks for the aggregate size of all
transferred files. It supports the following options:
min: Sets the minimum aggregate file size. This option defines the minimum aggregate file size to be transferred.
-
max: Sets the maximum aggregate file size.
This option limits the aggregate file size of all transferred files, but not the file size of individual files.
-
bytestring: Defines whether a failure is to return a user-friendly number or the plain file size.
This option defines whether the user sees '10864' or '10MB'. The default value is
TRUE, so '10MB' is returned if you did not specify otherwise.
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 404. Using the FilesSize Validator
<?php
$upload = new Zend_File_Transfer();
// Limit the size of all files to be uploaded to 40000 bytes
$upload->addValidator('FilesSize', false, 40000);
// Limit the size of all files to be uploaded to maximum 4MB and mimimum 10kB
$upload->addValidator('FilesSize',
false,
array('min' => '10kB', 'max' => '4MB'));
// As before, but returns the plain file size instead of a user-friendly string
$upload->addValidator('FilesSize',
false,
array('min' => '10kB',
'max' => '4MB',
'bytestring' => false));
Note
Note that this validator internally stores the file size of checked files. The file which exceeds the size will be returned as an error.




