1

Is there any available, "independent" function which could replace mime_content_type()?

On my new hosting I'm getting error:
Fatal error: Call to undefined function mime_content_type() in download.php on line 3

finfo_file doesn't work as well...

Sarah
  • 261
  • 2
  • 7
  • 13
  • 1
    See my answer to http://stackoverflow.com/questions/2006632/php-how-can-i-check-if-a-file-is-mp3-or-image-file/2006664#2006664 – Gordon Jan 13 '11 at 13:33
  • *(related)* http://www.mediawiki.org/wiki/Manual:Mime_type_detection#MIME_detection – Gordon Jan 13 '11 at 13:46

2 Answers2

1

Just mimic the function in your compat.php if you have one

if(!function_exists("mime_content_type"))
{
    function mime_content_type($file)
    {
        $open_bit = finfo_open(FILEINFO_MIME_TYPE);
        return finfo_file($open_bit, $file);
    }
}

The above function (FileInfo) is a PECL extension and is encouraged by PHP To use as an alternative, if you do not have the extension installed you can do the following:

  • Find the url to the latest version of fileinfo from http://pecl.php.net/package/Fileinfo
  • Download, compile and install
  • Run the following commands
    • wget http://pecl.php.net/get/Fileinfo-X.X.X.tgz
    • gunzip Fileinfo-X.X.X.tgz
    • tar -xvf Fileinfo-X.X.X.tar
    • cd fileinfo-X.X.X
    • ./configure
    • make
    • make install
  • Enable the extension by adding extension=fileinfo.so to your php.ini
  • Restart your web server and it should be working. And then proceed as normal
RobertPitt
  • 54,473
  • 20
  • 110
  • 156
0

As a matter of fact, there are two indepent implementations. One in http://upgradephp.berlios.de/ and one in PHP_Compat. You need the mime-magic file in either case.

mario
  • 138,064
  • 18
  • 223
  • 277