Issues

ZF-7242: *_MimeType:isValid() - doesn't use finfo when possible

Description

This problem is also seen in Zend_Transfer_Adapter_Abstract::getMimeType().

finfo will not be used to determine mime type because the magic file and the 'MAGIC' constant isn't set. However finfo works without this in php 5.3. So the mime type uses one of the lesser methods.

Comments

finfo works also in 5.2.4 without setting the magic constant.

When you want to use a own magic file you must also set the related option. There is no way to detect which mime database you want to use when you don't set it and your php.ini does also not give a proper location.

This is not a ZF issue, this is just a mis-configuration of your php.ini file. See the ZF documentation for details.

Can I suggest the documentation be changed then? It isn't consistent with how the finfo constructor behaves... {quote} Name of a magic database file, usually something like /path/to/magic.mime. If not specified, the MAGIC environment variable is used. If this variable is not set either, /usr/share/misc/magic is used by default. A .mime and/or .mgc suffix is added if needed. {quote}

Surely it would be easy to assign the browser given mime type to $this->_type by default and then replace it if finfo is available and can be constructed or if mime_content_type() is available. This would create more consistency with finfo itself and allow more people to use it without making demands of their php.ini file that aren't actually a requirement (or mis-configuration) by finfo/PHP.

How finfo behaves depends on your OS and your settings. When you have not configured finfo properly there is no way for ZF to use it.

The magic constant defines when the magic file can be found. There is no way to find this file automatically.

Still, when you have problems with finfo you should first take a look into php's finfo manual page. ZF should not double php's manual on how extensions should be configured.

Changed recognition of finfo with r16645