Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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));
like image 385
Jobynad Avatar asked Aug 26 '10 20:08

Jobynad


People also ask

How do I enable Fileinfo extension?

Follow the below steps to enable fileinfo extension with just few clicks. Step 1 : Login to your CPanel account. Step 2 : Select PHP version under software or search php version using search box. Step 3 : Below the PHP version you will see the fileinfo which in default not checklist yet.

What is Fileinfo PHP extension?

Advertisements. FileInfo functions module can try to guess a content type and encoding of a file by looking for certain magic byte sequences at a specific position within a file. While it's not a bulletproof approach, the heuristics used to do a very good job.


3 Answers

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

like image 82
jdehaan Avatar answered Sep 28 '22 00:09

jdehaan


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

like image 45
binhhoang18 Avatar answered Sep 28 '22 01:09

binhhoang18


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.

like image 35
Jordan Running Avatar answered Sep 28 '22 02:09

Jordan Running