예제 #1
0
 /**
  * @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());
 }
 /**
  * Ensures that the validator follows expected behavior
  *
  * @return void
  */
 public function testBasic()
 {
     $_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), 'test3' => array('name' => 'test3', 'type' => 'text3', 'size' => 203, 'tmp_name' => 'tmp_test3', 'error' => 2), 'test4' => array('name' => 'test4', 'type' => 'text4', 'size' => 204, 'tmp_name' => 'tmp_test4', 'error' => 3), 'test5' => array('name' => 'test5', 'type' => 'text5', 'size' => 205, 'tmp_name' => 'tmp_test5', 'error' => 4), 'test6' => array('name' => 'test6', 'type' => 'text6', 'size' => 206, 'tmp_name' => 'tmp_test6', 'error' => 5), 'test7' => array('name' => 'test7', 'type' => 'text7', 'size' => 207, 'tmp_name' => 'tmp_test7', 'error' => 6), 'test8' => array('name' => 'test8', 'type' => 'text8', 'size' => 208, 'tmp_name' => 'tmp_test8', 'error' => 7), 'test9' => array('name' => 'test9', 'type' => 'text9', 'size' => 209, 'tmp_name' => 'tmp_test9', 'error' => 8));
     $validator = new Zend_Validate_File_Upload();
     $this->assertFalse($validator->isValid('test'));
     $this->assertTrue(array_key_exists('fileUploadErrorAttack', $validator->getMessages()));
     $validator = new Zend_Validate_File_Upload();
     $this->assertFalse($validator->isValid('test2'));
     $this->assertTrue(array_key_exists('fileUploadErrorIniSize', $validator->getMessages()));
     $validator = new Zend_Validate_File_Upload();
     $this->assertFalse($validator->isValid('test3'));
     $this->assertTrue(array_key_exists('fileUploadErrorFormSize', $validator->getMessages()));
     $validator = new Zend_Validate_File_Upload();
     $this->assertFalse($validator->isValid('test4'));
     $this->assertTrue(array_key_exists('fileUploadErrorPartial', $validator->getMessages()));
     $validator = new Zend_Validate_File_Upload();
     $this->assertFalse($validator->isValid('test5'));
     $this->assertTrue(array_key_exists('fileUploadErrorNoFile', $validator->getMessages()));
     $validator = new Zend_Validate_File_Upload();
     $this->assertFalse($validator->isValid('test6'));
     $this->assertTrue(array_key_exists('fileUploadErrorUnknown', $validator->getMessages()));
     $validator = new Zend_Validate_File_Upload();
     $this->assertFalse($validator->isValid('test7'));
     $this->assertTrue(array_key_exists('fileUploadErrorNoTmpDir', $validator->getMessages()));
     $validator = new Zend_Validate_File_Upload();
     $this->assertFalse($validator->isValid('test8'));
     $this->assertTrue(array_key_exists('fileUploadErrorCantWrite', $validator->getMessages()));
     $validator = new Zend_Validate_File_Upload();
     $this->assertFalse($validator->isValid('test9'));
     $this->assertTrue(array_key_exists('fileUploadErrorExtension', $validator->getMessages()));
     $validator = new Zend_Validate_File_Upload();
     $this->assertFalse($validator->isValid('test1'));
     $this->assertTrue(array_key_exists('fileUploadErrorAttack', $validator->getMessages()));
     $validator = new Zend_Validate_File_Upload();
     $this->assertFalse($validator->isValid('tmp_test1'));
     $this->assertTrue(array_key_exists('fileUploadErrorAttack', $validator->getMessages()));
     $validator = new Zend_Validate_File_Upload();
     $this->assertFalse($validator->isValid('test000'));
     $this->assertTrue(array_key_exists('fileUploadErrorFileNotFound', $validator->getMessages()));
 }
 /**
  * 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);
 }