コード例 #1
0
	public function testErrorInFile()
	{
		$f = new PropertyFile('File name', 'some/path');
		$this->assertTrue($f->validate(''));
		
		$upload = new MockFileUpload('some/new/file', 500, UPLOAD_ERR_PARTIAL, 'some/older/session/file.ext');
		$f->set($upload);
		$this->assertFalse($f->validate(''));
		$this->assertEquals('The file transfer was not complete, please try again', $f->errors());
		$this->assertEquals('data/.session/some/older/session/file.ext', $f->get());
		$this->assertEquals('ext', $f->extension());
		$f->error(null);
		
		
		$upload = new MockFileUpload('some/new/file', 500, UPLOAD_ERR_INI_SIZE, 'some/older/session/file');
		$f->set($upload);
		$this->assertFalse($f->validate(''));
		$this->assertEquals('The filesize is too large', $f->errors());
		$this->assertEquals('data/.session/some/older/session/file', $f->get());
		$f->error(null);
		
		$upload = new MockFileUpload('some/new/file', 500, UPLOAD_ERR_CANT_WRITE, 'some/older/session/file');
		$f->set($upload);
		$this->assertFalse($f->validate(''));
		$this->assertEquals('The file upload failed, please try again', $f->errors());
		$this->assertEquals('data/.session/some/older/session/file', $f->get());
		$f->error(null);
	}
コード例 #2
0
ファイル: file.class.php プロジェクト: nathansamson/CoOrg
	public function validate($for)
	{
		$v = parent::validate($for);
		
		if ($v == true)
		{
			if ($this->_value instanceof IFileUpload && $this->_value->error() == UPLOAD_ERR_OK)
			{
				$size = @getimagesize($this->_value->temppath());
				if ($size == false)
				{
					$this->_value->invalidUpload();
					$this->error(t('This is not a valid image file (only png, jpeg and gif are supported)'));
					return false;
				}
				else if (!self::isSupported($size[2]))
				{
					$this->_value->invalidUpload();
					$this->error(t('This is not a valid image file (only png, jpeg and gif are supported)'));
					return false;
				}
				else if ($size[0] > $this->_maxX || $size[1] > $this->_maxY)
				{
					$this->_value->invalidUpload();
					$this->error(t('The file resolution is too large, maximum is %x x %y', array('x'=>$this->_maxX, 'y'=>$this->_maxY)));
					return false;
				}
			}
			return true;
		}
		else
		{
			return false;
		}
	}