mime_content_type() not recognized by MAMP 1.9 Pro PHP 5.2.13
I'm a PHP and MAMP newbie. I've got a PHP 5.2.13 site I'm supporting which calls out to the mime_content_type() function, but that function is not recognized on my machine. I keep getting this:
Fatal error: Call to undefined function mime_content_type()
The googles all say indecipherable things about "mime magic". Is there some extension I need to install in my MAMP PHP instance so 开发者_开发问答that mime_content_type() will be recognized?
The function mime_content_type
is deprecated in favor of Fileinfo, which is a PECL extension that has recently been moved into PHP's source. You can try using Fileinfo and see if it's available; it's installed by default since PHP 5.3.0. However, if you're using an older version or changed some configuration or something, you might have to install it.
Try the code below. If it works, you're done; if it doesn't, you'll have to install Fileinfo. The package is described here.
Using Fileinfo, you would replace $type=mime_content_type($filename)
, for example, with:
$finfo=finfo_open(FILEINFO_MIME_TYPE);
$type=finfo_file($finfo, $filename);
finfo_close($finfo);
It's been deprecated for a while now. You're better off writing your own function, or taking some hints from the docs and comments on php.net
精彩评论