PHP fileinfo is undefined function
Asked Answered
T

8

65

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));
Trainer answered 26/8, 2010 at 20:8 Comment(1)
Not an issue with php or laravel, your probably using namespaced code which means you need to import the class <?php namespace Your\Namespace; use finfo;Horsley
T
95

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

Tapping answered 26/8, 2010 at 20:10 Comment(2)
$mime_type return a string which contains <mime type>; charset=<charset> , so to get actual file mime type I have modified the question.Hang
I use this gist that can be updated with the build script also found here.Checkerwork
C
28

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

Cowlick answered 4/7, 2014 at 1:30 Comment(0)
F
21

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.

Fortunato answered 26/8, 2010 at 20:12 Comment(0)
T
9

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

Twoup answered 6/12, 2013 at 6:36 Comment(0)
R
7

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.

Reticular answered 2/6, 2016 at 20:14 Comment(0)
A
1

For those have had it working fine, but then this error appears:

Some hosting providers (e.g., Dreamhost) allow customers to override default PHP settings in a configuration file, often with a path something like:

~/.php/5.4/phprc

That version number in the path can be a problem if you upgrade PHP (or it is upgraded on your behalf). Any custom settings from the prior version, including one enabling the fileinfo extension, will be missing in the newer version. Usually you can just copy the config file to the appropriate new config directory and restart the server.

Alford answered 6/11, 2016 at 22:22 Comment(0)
S
1

I had this same issue with PHP.I did the following steps:

 - make sure that the fileinfo extension is already installed if you are using < PHP 5.3.0.

 - Then you have to add in php.ini ;extension=fileinfo.so or
   ;extension=php_fileinfo.dll

 -  If you want to uncomment remove the semicolon(;)
   extension=fileinfo.so or extension=php_fileinfo.dll

Then save and restart your web server.

Spice answered 20/4, 2017 at 4:59 Comment(0)
N
0

For PHP 7.3 or Higher

Change

;extension=fileinfo

To

extension=fileinfo

in php.ini file.

Nuclease answered 19/11, 2020 at 9:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.