ZF-5709: File extension to MIME type database

Description

We should have the database of MIME types with relation to file extensions in Zend_MIME for use of various modules such as file transfer services, etc. It seems to be the most logical place to put such thing to.

This can be further extended by having finfo (file magic) interface which will guess file MIME not only but extension but also content. finfo is in standard PHP starting 5.3 but in PECL before that.

Comments

This could also help replace the getMimeType() method on Zend_Service_Amazon_S3, which converts file extensions to mime types.

There's a great list of file extensions and mime types in one of the apache config files: http://svn.apache.org/viewvc/httpd/… Maybe we could use that one.The last comment says it's in the public domain.

Beside finfo (which is part of PHP 5.3 IIRC) we can also use getimagesize().

I see how I get time to write a little guesser class. But I don't have a problem if anyone else is quicker ;)

It seems to be also one of issues for next major release like as ZF-1490 . Do you have any idea ?

IMO, it seems to be better that we would submit a new proposal. Because I think this issue might be new feature rather than expansion of existing Zend_Mime.

I expect the class name with Zend_Filter_File_MimeType as one of converters about file's infomation, or Zend_Mime_Type as specialty handler of Mime types.

The class might have 2 kinds method.

1) Simple converter from file's extension to MIME type. for example, getTypeByExtension(). it may be required for getMimeType() of Zend_Service_Amazon_S3 (mentioned by thing2b).

2) Information extracter from file with finfo() or getimagesize(). For example, getTypeByFinfo(). Or we might substitute it by getMimeType() of Zend_File_Transfer_Adapter

I hope it could help you ;)

Note that Zend_Filter is not the correct component for getting the mimetype of an file.

Detaching Zend_Filter

Note that finfo is availalble also to 5.2.4 installations.

Zend_Mime was designed ONLY for usage with Zend_Mail. Therefor it is not used in other places of the framework.

Note that Zend_File_Transfer is ONLY for usage while transferring a file, and not for existing files somewhere in a directory. When you let file-transfer detect the mime type based on the extension as proposed abbove it's a VERY HUGE security risk.

The base question is, if we want to couple two components more together for a functionallity which is available within vanilla PHP installations. I would say no.

You say that "Zend_Mime was designed ONLY for usage with Zend_Mail." If this is the case, why was Zend_Mime not called Zend_Mail_Mime?

Thank You opinions, Thomas and thing2b .

I will be happy if reporter or participants would submit proposal. Because the MIME type database seems to be independent with the existing Zend_Mime functions and also Zend_Mail one.

Rather, it is required with other components. It would be better to ask review for many reviewers about the database .

I don't see why Zend_Mime can't be used whenever we need to do something with MIME. What in Zend_Mime prevents us from using it anywhere we want to?

BTW, having good list of MIME types for files can help mailing too, if you are mailing files. But doesn't have to be for mail exclusively.

So what the results of this talking? I'm also interested to have tools to work with mime, and as we all can see this tools implemented in wide range of components, and all this components has its own realisation.

Sorry, I became inactive since last April.