Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call to undefined function Illuminate\Filesystem\finfo_file()

Tags:

php

laravel

I have the following error showing up in my laravel.log file on a website I have running. How can I pin down where the error originates from? As the stack trace is so short I am unsure where to start.

[2017-07-03 16:05:13] production.ERROR: exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message 'Call to undefined function Illuminate\Filesystem\finfo_file()' in /home/uksacbor/laravel-projects/attestation/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php:254 Stack trace: #0 {main}

I've ran a search on the site's folder using sublime's global search for when finfo_file() is used and I've used it in a helper in a test...

private function prepareFileUpload($path, $name)
{
    TestCase::assertFileExists($path);

    $pathInfo = pathinfo($path);

    $copyPath = $pathInfo['dirname'] . $pathInfo['filename'] . '_copy' . $pathInfo['extension'];

    \File::copy($path, $copyPath);

    $finfo = finfo_open(FILEINFO_MIME_TYPE);

    $mime = finfo_file($finfo, $copyPath);

    return new \Illuminate\Http\UploadedFile($copyPath, $name, $mime, filesize($copyPath), null, true);
}

Currently, my tests are all passing.

Any ideas?

like image 700
haakym Avatar asked Jul 05 '17 14:07

haakym


3 Answers

You should install fileinfo using WHM or DirectAdmin

enter image description here

like image 109
DolDurma Avatar answered Sep 28 '22 11:09

DolDurma


When you are managing the server yourself you should run

sudo pecl install fileinfo

from the commandline and edit php.ini (probably located at /etc/php.ini)

to contain the line

extension=fileinfo.so

don't forget to restart the web server. Depending on your os and web stack this is something like

  • service apache restart
  • service httd restart
  • service nginx restart

When using a shared hosting, you probably have an option in the webinterface to enable it from there. For example in directadmin

Advanced features > Select PHP version

enter image description here

And then

Tick the checkbox next to fileinfo

enter image description here

Don't forget to click save

like image 8
online Thomas Avatar answered Nov 01 '22 19:11

online Thomas


You are supposed to activate finfo_file()

[check this link]

like image 3
Michael Hamisi Avatar answered Nov 01 '22 18:11

Michael Hamisi