2012-02-27 2 views
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); 

答えて

0

投稿したコードは、コントローラ用ではなくフォーム用のように見えます本当に助けてくれない。

ここでの例#2の下

if (!$upload->isValid($file)) { 
    print "Sorry but $file is not what we wanted"; 
    continue; 
} else echo 'File '.$info['name'].' is not allowed'; 

詳細情報:File Upload using zend framework 1.7.4

if文秒で http://framework.zend.com/manual/en/zend.file.transfer.introduction.html#zend.file.transfer.introduction.checking

、あなたは、単にファイル名を取得することができます

関連する問題