Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing Apache's Mime-Type to Extension Mapping

Does PHP expose Apache's Mime-Type to extension mapping in any way shape or form.

That is, Apache typically has a list of files extensions (.gif, .pdf) that it maps to a list of Mime-Types (image/gif, application/pdf, etc.) in a file typically called mime.types. Is there anyway to get a list of these mapings for the current running apache process via PHP?

Lacking that, is there a way for PHP to ask Apache which mime.type file it's using?

like image 726
Alan Storm Avatar asked Nov 05 '22 14:11

Alan Storm


1 Answers

You're probably running php as a CGI, but if you are using mod_php and the file is accessible via a url, you can take a look at:

http://us2.php.net/manual/en/function.apache-lookup-uri.php

Or if you aren't limited by openbasedir restrictions, you could loop over file('/usr/local/apache2/conf/mime.types')

like image 169
Mark Avatar answered Nov 11 '22 06:11

Mark