1
使用zend时添加验证程序以验证文件大小和扩展名。是否可以跟踪文件名和上传文件的大小。可以获取大小和文件名,即使验证失败。当验证失败时我无法跟踪文件名,因为文件在验证失败时未进入临时目录。是在存储在临时目录中之前验证的文件如何在使用zend addvalidator验证该文件之前获取上传的文件名和大小
这是我的代码片段:
$document_path_field = $this->CreateElement('file','document_path');
$document_path_field->setLabel('Document');
$document_path_field->setAttrib('class','button');
//$document_path_field->setDestination(SUPPORTING_DOCUMENT_DIRECTORY);
$document_path_field->addValidator('Count', false, 1);
$document_path_field->addPrefixPath('Course_Validate_File', 'Course/validate/File', 'validate');
$document_path_field->addValidator('Size', false, 1000000);
$document_path_field->addPrefixPath('Course_Validate_File', 'Course/validate/File', 'validate');
$document_path_field->addValidator('CheckExtension',false,'docx,doc,jpg,png,gif,pdf');
$document_path_field->clearDecorators();
if(isset($field_required_array['document_path']) && $field_required_array['document_path'] == "Yes")
{
$document_path_field->setRequired(true);
}
else
{
$document_path_field->setRequired(false);
}
$document_path_field->setDecorators($this->setFieldElementDecorators());
if(in_array('document_path',$field_names_array))
{
array_push($form_elements,$document_path_field);
}
$current_document_path = $this->CreateElement('hidden','current_document_path');
$current_document_path->setLabel('Current Document')
->clearDecorators()
->addDecorator($imageviewScript)
->setValue($this->_document_path);
array_push($form_elements,$current_document_path);