1
ファイルサイズと拡張子を検証するためにzend addバリデータを使用する場合アップロードされたファイルのファイル名とサイズを追跡できますサイズとファイル名は検証に失敗した場合でも有効です。検証に失敗した場合、検証が失敗したときにファイル名を追跡できません。一時ディレクトリに保存する前にファイルを検証しますか?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);