Search code examples
phplaravellaravel-5mime

Laravel 5 - get MIME type from file extension


In Laravel 5 how can I get MIME type from extension? Even better if there's a way to convert array of extensions to array of mimes.

E.g. how to convert array('doc', 'xls') to array('application/msword', 'application/vnd.ms-excel')?


Solution

  • When "guzzlehttp/guzzle": "~5.3|~6.0" is in your composer.json, you can use this:

    $mimetype = \GuzzleHttp\Psr7\mimetype_from_filename('foo.doc');
    $mimetype = \GuzzleHttp\Psr7\mimetype_from_extension('doc');