Question

I try to add a validator for the length of the filename which is uploaded from my Zend form. I don't know whether I should add this validator in the form itself or to the Zend_File_Transfer_Adapter_Http handling the upload. However, right now I'm trying the second thing - see code below. I want the controller to redirect with an error flag if the length of the filename to be uploaded exceeds 40 chars.

$upload results in being valid even with a 41 chars long filename - why?

$upload = new Zend_File_Transfer_Adapter_Http();

$upload->addValidators(
        array(
            array('validator' => 'StringLength', 'options' => array(
                'min' => 0,
                'max' => 40))
        )
);

if (!$upload->isValid()) {
    $this->_redirect('/customer/uploadfile/groupid/'.$groupId.'/flag/XXX-TODO-Failure');
}
Was it helpful?

Solution

It looks like you're not validating anything with the code you have shown.

change the line as follows to reference the filename such as...

if(!$upload->isValid( $filenameToValidate ) {

... }

Also remember the filename is not a post but will be found in the $_FILES superglobal.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top