通过 PHP 获取 MIME 类型

我可以在本地访问文件,我需要获取它们的 MIME 类型.在 WAMP/LAMP、CodeIgniter 和 Zend 库中工作.获取 MIME 类型信息的最佳方法是什么?

I have local access to files, which I need to get their MIME types. Working in WAMP/LAMP, CodeIgniter, and Zend libraries. What's the best way to get MIME type information?

推荐答案

没有简单的方法.你可以试试:
http://www.php.net/manual/en/function.finfo-file.php

There's no easy way. You could try:
http://www.php.net/manual/en/function.finfo-file.php

// return mime type ala mimetype extension
$finfo = finfo_open(FILEINFO_MIME_TYPE);

当然,这假设您可以安装 PECL 扩展.

Of course, this assumes you can install PECL extensions.

相关文章