PhpRiot
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

Zend_File_Transfer

Changes when using filters and validators

As noted by users, the validators from Zend_File_Transfer do not work in conjunction with Zend_Config due to the fact that they have not used named arrays.

Therefor, all filters and validators for Zend_File_Transfer have been reworked. While the old signatures continue to work, they have been marked as deprecated, and will emit a PHP notice asking you to fix them.

The following list shows you the changes you will have to do for proper usage of the parameters.

Filter: Rename
  • Old method API: Zend_Filter_File_Rename($oldfile, $newfile, $overwrite)

  • New method API: Zend_Filter_File_Rename($options) where $options accepts the following array keys: source equals to $oldfile, target equals to $newfile, overwrite equals to $overwrite.

Example 1081. Changes for the rename filter from 1.6 to 1.7

// Example for 1.6
$upload = new Zend_File_Transfer_Adapter_Http();
$upload->addFilter('Rename',
                   array('/path/to/oldfile', '/path/to/newfile', true));

// Same example for 1.7
$upload = new Zend_File_Transfer_Adapter_Http();
$upload->addFilter('Rename',
                   array('source' => '/path/to/oldfile',
                         'target' => '/path/to/newfile',
                         'overwrite' => true));

Validator: Count
  • Old method API: Zend_Validate_File_Count($min, $max)

  • New method API: Zend_Validate_File_Count($options) where $options accepts the following array keys: min equals to $min, max equals to $max.

Example 1082. Changes for the count validator from 1.6 to 1.7

// Example for 1.6
$upload = new Zend_File_Transfer_Adapter_Http();
$upload->addValidator('Count',
                      array(2, 3));

// Same example for 1.7
$upload = new Zend_File_Transfer_Adapter_Http();
$upload->addValidator('Count',
                      false,
                      array('min' => 2,
                            'max' => 3));

Validator:Extension
  • Old method API: Zend_Validate_File_Extension($extension, $case)

  • New method API: Zend_Validate_File_Extension($options) where $options accepts the following array keys: * equals to $extension and can have any other key, case equals to $case.

Example 1083. Changes for the extension validator from 1.6 to 1.7

// Example for 1.6
$upload = new Zend_File_Transfer_Adapter_Http();
$upload->addValidator('Extension',
                      array('jpg,gif,bmp', true));

// Same example for 1.7
$upload = new Zend_File_Transfer_Adapter_Http();
$upload->addValidator('Extension',
                      false,
                      array('extension1' => 'jpg,gif,bmp',
                            'case' => true));

Validator: FilesSize
  • Old method API: Zend_Validate_File_FilesSize($min, $max, $bytestring)

  • New method API: Zend_Validate_File_FilesSize($options) where $options accepts the following array keys: min equals to $min, max equals to $max, bytestring equals to $bytestring.

Additionally, the useByteString() method signature has changed. It can only be used to test if the validator is expecting to use byte strings in generated messages. To set the value of the flag, use the setUseByteString() method.

Example 1084. Changes for the filessize validator from 1.6 to 1.7

// Example for 1.6
$upload = new Zend_File_Transfer_Adapter_Http();
$upload->addValidator('FilesSize',
                   array(100, 10000, true));

// Same example for 1.7
$upload = new Zend_File_Transfer_Adapter_Http();
$upload->addValidator('FilesSize',
                      false,
                      array('min' => 100,
                            'max' => 10000,
                            'bytestring' => true));

// Example for 1.6
$upload->useByteString(true); // set flag

// Same example for 1.7
$upload->setUseByteSting(true); // set flag

Validator: Hash
  • Old method API: Zend_Validate_File_Hash($hash, $algorithm)

  • New method API: Zend_Validate_File_Hash($options) where $options accepts the following array keys: * equals to $hash and can have any other key, algorithm equals to $algorithm.

Example 1085. Changes for the hash validator from 1.6 to 1.7

// Example for 1.6
$upload = new Zend_File_Transfer_Adapter_Http();
$upload->addValidator('Hash',
                   array('12345', 'md5'));

// Same example for 1.7
$upload = new Zend_File_Transfer_Adapter_Http();
$upload->addValidator('Hash',
                      false,
                      array('hash1' => '12345',
                            'algorithm' => 'md5'));

Validator: ImageSize
  • Old method API: Zend_Validate_File_ImageSize($minwidth, $minheight, $maxwidth, $maxheight)

  • New method API: Zend_Validate_File_FilesSize($options) where $options accepts the following array keys: minwidth equals to $minwidth, maxwidth equals to $maxwidth, minheight equals to $minheight, maxheight equals to $maxheight.

Example 1086. Changes for the imagesize validator from 1.6 to 1.7

// Example for 1.6
$upload = new Zend_File_Transfer_Adapter_Http();
$upload->addValidator('ImageSize',
                      array(10, 10, 100, 100));

// Same example for 1.7
$upload = new Zend_File_Transfer_Adapter_Http();
$upload->addValidator('ImageSize',
                      false,
                      array('minwidth' => 10,
                            'minheight' => 10,
                            'maxwidth' => 100,
                            'maxheight' => 100));

Validator: Size
  • Old method API: Zend_Validate_File_Size($min, $max, $bytestring)

  • New method API: Zend_Validate_File_Size($options) where $options accepts the following array keys: min equals to $min, max equals to $max, bytestring equals to $bytestring.

Example 1087. Changes for the size validator from 1.6 to 1.7

// Example for 1.6
$upload = new Zend_File_Transfer_Adapter_Http();
$upload->addValidator('Size',
                      array(100, 10000, true));

// Same example for 1.7
$upload = new Zend_File_Transfer_Adapter_Http();
$upload->addValidator('Size',
                      false,
                      array('min' => 100,
                            'max' => 10000,
                            'bytestring' => true));

Zend Framework