在我的表单中,我有一个文件上传验证器,如下面的代码所示。我面临的问题是适配器总是在验证时向我发送错误。我的问题是我错过了什么?
下面是代码示例和输出;
# Set form data
$form->setValidationGroup('firstname', 'lastname');
$form->setData($request->getPost());
# Get file uploads
$file = $this->params()->fromFiles('avatar');
# Set image validators
$size = new Size(array('min' => 0, 'max' => 1024000)); // 5kb / 500kb
$extension = new Extension(array('jpg', 'jpeg', 'gif', 'png'));
$adapter = new \Zend\File\Transfer\Adapter\Http();
$adapter->setValidators(array($size, $extension), $file['name']);
Debug::dump($file);
Debug::dump($adapter->isValid());
Debug::dump($adapter->getMessages());
exit();
Output;
array(5) {
["name"] => string(10) "avatar.png"
["type"] => string(9) "image/png"
["tmp_name"] => string(14) "/tmp/phptkaBvc"
["error"] => int(0)
["size"] => int(171961)
}
bool(false)
array(1) {
["fileUploadErrorNoFile"] => string(24) "File '' was not uploaded"
}
此致 NIK