public function testMimeType() { $element = new Zend_Form_Element_File('baz'); $adapter = new Zend_Form_Element_FileTest_MockAdapter(); $element->setTransferAdapter($adapter); $this->assertEquals('text/plain', $element->getMimeType('baz.text')); }
/** * Replace item * * @param string $key * @param Zend_Form_Element_File $file * @return void * @throws InvalidArgumentException */ public function replaceItem($key, \Zend_Form_Element_File $file) { $oldMime = current(explode(';', $this->storage->getMimeType($key))); $newMime = current(explode(';', $file->getMimeType())); if ($oldMime != $newMime && !(in_array($oldMime, self::$equivalentMimeTypes) && in_array($newMime, self::$equivalentMimeTypes))) { throw new \InvalidArgumentException(sprintf('You can only replace a file with a file of the same type. The original file is of type "%s", and the file you uploaded was of type "%s".', $oldMime, $newMime)); } $this->storage->storeItem($key, file_get_contents($file->getFileName())); }