PHP fileinfo is undefined function

Whenever I try to get the mime content type from php, it echos:

Fatal error: Class 'finfo' not found in /home/jobynadel/finadel.com/video/finfo.php on line 4

or

Fatal error: Call to undefined function finfo_open in /home/jobynadel/finadel.com/video/finfo.php on line 4

I just can't figure it out!

The code I am using is:

$file_info = new finfo(FILEINFO_MIME_TYPE);
// See constant value http://php.net/manual/en/fileinfo.constants.php#113687 
$mime_type = $file_info->buffer(file_get_contents($file));

Solution 1:

Have a look at your php.ini file and check that the fileinfo.soor php_fileinfo.dll is activated (depending on your platform and version).

There should be a line similar to

extension=fileinfo.so

in your php.ini file

Solution 2:

If you using XAMPP, you enable extension=php_fileinfo.dll in php.ini

Solution 3:

What version of PHP do you have? PHP 5.3.0 and later have Fileinfo built in, but on Windows you must enable it manually in your php.ini. You can find further information in the documentation.

Solution 4:

If you are using WAMP then Go to PHP extensions and enbale PHP_fileinfo and restart all serverices.

Solution 5:

Windows users: just edit php.ini and uncomment this line:

extension=php_fileinfo.dll

I.e. remove the preceding semicolon from

;extension=php_fileinfo.dll

Remember to restart Apache for new php.ini to take effect.