6

I am having a problem getting File Info working. It is enabled in PHP.ini but when I run a php -m it is not listed. I have PHP 5.5 so it should be standard and not need the pecl. I am a newbie and confused so please be kind.

php -m

[PHP Modules]
bcmath
calendar
Core
ctype
curl
date
dom
ereg
exif
filter
ftp
gd
gettext
hash
iconv
imagick
imap
ionCube Loader
json
libxml
mbstring
mcrypt
mysql
openssl
pcre
Phar
posix
Reflection
session
SimpleXML
sockets
SPL
sqlite3
standard
tokenizer
XCache
XCache Cacher
xml
xmlreader
xmlwriter
zip
zlib

[Zend Modules]
XCache
XCache Cacher
the ionCube PHP Loader

In my PHP.ini

extension = "fileinfo.so"
Chris
  • 195
  • 1
  • 4
  • 17
  • Check what `php.ini` is actually used. It might not be the one you think. – CBroe Sep 27 '15 at 17:55
  • I think you should locate the right php.ini try running php --ini – fefe Sep 27 '15 at 17:55
  • By default this extension gets built in to PHP since 5.3, there is no `so` file you need to load. Did you build PHP yourself or install from a package manager? Does the output of the `configure command` in your PHP info show `--disable-fileinfo` which would disable it from being included with PHP in which case you would need to compile and install the PECL module. – drew010 Sep 27 '15 at 18:02
  • Yes, thanks. Needed to be recompiled with FileInfo enabled! – Chris Sep 27 '15 at 18:12
  • @Chris Glad that was it. I added it as an answer so it may be easier for people to find in the future. – drew010 Sep 27 '15 at 19:51
  • 1
    Enable `php_fileinfo.dll` in `php.ini` and restart your server. – ako Sep 02 '17 at 08:39
  • https://github.com/brandonsavage/Upload/issues/69#issuecomment-326731455 – ako Sep 02 '17 at 08:45

4 Answers4

6

By default this extension gets built in to PHP since 5.3, meaning there is no so to load.

Since it is not showing as an available module, it may mean PHP was compiled with the --disable-fileinfo switch (look at the Configure Command output in phpinfo) which would disable it from being included with PHP.

If it was compiled with the disable finfo option, you will either need to recompile PHP without that option, or compile and install the PECL module and then dynamically load the extension in php.ini.

drew010
  • 68,777
  • 11
  • 134
  • 162
  • how to compile and install it with PECL module? when I update or install PHP it just simply install it and do not give me any option to selection extensions. but I am having PECL module it is shoing file_infopath is the same module? – Sayed Mohd Ali Jul 22 '19 at 09:49
  • Ok, installed CodeGen_PECL module via PEAR now I want to know how to dynamically load it into php.ini – Sayed Mohd Ali Jul 22 '19 at 10:08
2

I had same error as the OP on a cPanel host. The solution was to go into my web hosting control panel, select "Select PHP Version" and then enable the "fileinfo" extension.

miken32
  • 42,008
  • 16
  • 111
  • 154
ban-geoengineering
  • 18,324
  • 27
  • 171
  • 253
0

Just go to "Select PHP Version" in your cPanel and then go to "Extensions", search for "fileinfo", and then finally enable this feature and this will probably fix your problem like it did mine.

  • Hi Daniel You are assuming the OP has CPanel and this may not be the case. But, well, your answer can be helpful for future searchers with CPanel installed... Anyway, just a quick question: Did you note that this post is more than 6 years old? I think your collaboration will be more appreciated in recent posts, where there are more chances that the OP is still facing the issue. Thanks for collaborating with the community and welcome to Stackoverflow. – Just a nice guy Mar 17 '22 at 01:57
0

I encountered this problem in Laravel.

There are two solutions, both work:

  1. Import the class

     use finfo;
    
     $finfo = new finfo(FILEINFO_MIME_TYPE);
    
  2. Or put a leading \ if using a global class inside a namespace.

     $finfo = new \finfo(FILEINFO_MIME_TYPE);
    
Ilyich
  • 4,966
  • 3
  • 39
  • 27