Mohammad Ali Akbari
Mohammad Ali Akbari

Reputation: 10395

Zend File Validator return wrong message

below code return "File '' is not readable or does not exist" always:

$filters = array(
    '*' => 'stringTrim'
);
$validators = array(
    'image'=> array(
        'allowEmpty' => TRUE,
        new Zend_Validate_File_ImageSize(array('minheight'=>0,'minwidth'=>0,'maxheight'=>1024,'maxwidth'=>1024)),
    )
);
$input = new Zend_Filter_Input($filters, $validators);
$input->setData(array_merge($data, $_FILES));
if (!$input->isValid()) {
    $this->_errors = $input->getMessages();
}

Upvotes: 1

Views: 387

Answers (1)

Htbaa
Htbaa

Reputation: 2309

The input name of your file input has to be image. Also, be sure your form has enctype="multipart/form-data". The format of $_FILES is explained here.

Aside from that I don't detect any code in Zend_Validate_File_ImageSize that can operate on $_FILES. I think you've got to pass the actual path to the file, e.g. 'image' => $_FILES['image']['tmp_name'] (in your $input->setData() call).

Upvotes: 2

Related Questions