简体   繁体   中英

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?

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')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM