/**
  * Ensures that setFiles() returns expected value
  *
  * @return void
  */
 public function testSetFiles()
 {
     $files = array('test' => array('name' => 'test1', 'type' => 'text', 'size' => 200, 'tmp_name' => 'tmp_test1', 'error' => 0), 'test2' => array('name' => 'test2', 'type' => 'text2', 'size' => 202, 'tmp_name' => 'tmp_test2', 'error' => 1));
     $_FILES = array('test' => array('name' => 'test3', 'type' => 'text3', 'size' => 203, 'tmp_name' => 'tmp_test3', 'error' => 2));
     $validator = new Zend_Validate_File_Upload();
     $validator->setFiles(array());
     $this->assertEquals($_FILES, $validator->getFiles());
     $validator->setFiles();
     $this->assertEquals($_FILES, $validator->getFiles());
     $validator->setFiles($files);
     $this->assertEquals($files, $validator->getFiles());
 }
Exemple #2
0
 public function init()
 {
     // Задаём имя форме
     $this->setName('documentation');
     $description = new Zend_Form_Element_Text('description', array('class' => 'form-control'));
     $description->setRequired(true)->setAttrib('placeholder', 'Введите название:')->addFilter('StripTags')->addFilter('StringTrim')->addValidator('NotEmpty')->addValidator('regex', true, array("/^[A-Za-zА-Яа-я1-90 \\.\\-\\А\\П\\Н]{3,20}\$/i", 'messages' => $settings['messages']['error']))->addValidator('NotEmpty', true, array('messages' => array('isEmpty' => $settings['messages']['empty'])))->removeDecorator('label')->removeDecorator('element')->removeDecorator('errors');
     $validator = new Zend_Validate_File_Upload();
     $validator->setMessages(array('fileUploadErrorNoFile' => 'Файл не выбран!'));
     $file = new Zend_Form_Element_File('file');
     $file->setDestination(DATA_PATH . '/public/data/')->setRequired(true)->addValidator($validator);
     // Создаём элемент формы Submit c именем = submit
     $submit = new Zend_Form_Element_Submit('submit', array('class' => 'btn btn-default', 'id' => 'data_submit'));
     $this->addElements(array($description, $submit, $file));
 }
 /**
  * @group ZF-10738
  */
 public function testGetFilesReturnsEmptyArrayAfterSetFilesIsCalledWithNull()
 {
     $validator = new Zend_Validate_File_Upload();
     $validator->setFiles(NULL);
     $this->assertEquals(array(), $validator->getFiles());
 }
 /**
  *
  * @param type $messages_prefixed
  * @return \Zend_Validate_File_Upload 
  */
 protected function _getValidatorFileUpload($messages_prefixed = "")
 {
     $file = new Zend_Validate_File_Upload();
     $file->setMessage(sprintf($this->_translate('ERROR_FILE_NOT_UPLOADED'), $this->_translate($messages_prefixed)), Zend_Validate_File_Upload::NO_FILE);
     $file->setMessage(sprintf($this->_translate('ERROR_FILE_MAX_SIZE'), $this->_translate($messages_prefixed)), Zend_Validate_File_Upload::INI_SIZE);
     return $file;
 }
 /**
  * @group ZF-12128
  */
 public function testErrorMessage()
 {
     $_FILES = array('foo' => array('name' => 'bar', 'type' => 'text', 'size' => 100, 'tmp_name' => 'tmp_bar', 'error' => 7));
     $validator = new Zend_Validate_File_Upload();
     $validator->isValid('foo');
     $this->assertEquals(array('fileUploadErrorCantWrite' => "File 'bar' can't be written"), $validator->getMessages());
 }
Exemple #6
0
 /**
  * Checks if the file was already received
  *
  * @param  string|array $files (Optional) Files to check
  * @return bool
  */
 public function isReceived($files = null)
 {
     $validate = new Zend_Validate_File_Upload();
     if (!$validate->isValid($files)) {
         return false;
     }
     return true;
 }
 /**
  * Checks if the files are valid
  *
  * @param  string|array $files (Optional) Files to check
  * @return boolean      True if all checks are valid
  */
 public function isValid($files = null)
 {
     // Workaround for WebServer not conforming HTTP and omitting CONTENT_LENGTH
     $content = 0;
     if (isset($_SERVER['CONTENT_LENGTH'])) {
         $content = $_SERVER['CONTENT_LENGTH'];
     } else {
         if (!empty($_POST)) {
             $content = serialize($_POST);
         }
     }
     // Workaround for a PHP error returning empty $_FILES when form data exceeds php settings
     if (empty($this->_files) && $content > 0) {
         if (is_array($files)) {
             $files = current($files);
         }
         $temp = array($files => array('name' => $files, 'error' => 1));
         $validator = new Zend_Validate_File_Upload();
         $validator->setFiles($temp)->isValid($files, null);
         $this->_messages += $validator->getMessages();
         return false;
     }
     return parent::isValid($files);
 }