Search code examples
phpfile-typehuman-readable

Human readable file types


Files uploaded to an application have unusually long/complex file types. For example,

icantype.docx: 
application/vnd.openxmlformats-officedocument.wordprocessingml.document

lookieloo.pptx
application/vnd.openxmlformats-officedocument.presentationml.presentation

While I could grab the extension (which would normally be correct), I'm wondering if there is a cleaner way of getting a simple, short file type. I don't mind windows-centric file types, since my users are not ever uploading Libre docs. Using the same examples:

icantype.docx: 
Word

lookieloo.pptx
Power Point

Does something like this already exist in a built-in function? Or are there PECL or other classes that provide similar functionality?


Solution

  • I'm not finding a built in function to supply this information, but freeformatter.com put together a comprehensive and expanded list of MIME types and descriptions.

    I've extracted data from this page and put into machine-readable files. All credit to freeformatter.com.

    Pipe-delimited file (CSV), minus links under Details.
    http://dropbox.com/s/9a88b5iy9mue34l/mime_types_from_freeformatter.csv.

    ODS spreadsheet with the same data.
    http://dropbox.com/s/i6x9itln84r272o/mime_types_from_freeformatter.ods

    Here's a MySQL dump file with the same data (details link and text in separate colums): http://dropbox.com/s/l621lrhcpyu4beo/lookup_mime_type.sql