How to enable php_fileinfo extension in PHP?

佐手、 提交于 2020-06-25 04:15:13

问题


My Laravel app can't validate uploaded images. It returns this error message:

Unable to guess the mime type as no guessers are available (Did you enable the php_fileinfo extension?)

Laravel error message

I know enabling php_fileinfo.dll/php_fileinfo.so at php.ini fixes it. But I don't have access to my remote server's php.ini file.

So I thought is there any other way to enable it? And how? Maybe I can use PHP's ini_set() methods? I tried using it like:

ini_set('extension', 'php_fileinfo.so');

But it doesn't work.

I also read you can override php.ini settings using .htaccess files. But how?

As Laravel's default, my .htaccess file is:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    # Redirect Trailing Slashes...
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

How should you put such additionals in there?


回答1:


Create a .htaccess file where your root is and then do this

php_value extension=php_fileinfo.dll

or

php_admin_flag extension=php_fileinfo.dll



回答2:


create own php.ini file in root folder of your directory.

example if you are making changes on a server then it should be inside the public.html folder.

create file name php.ini it will override the settings. just add in the file

extension=php_fileinfo.dll



回答3:


If you only want to upload images then it might help you.

$image_size_info = @getimagesize($filename); //surpress errors(@) if not image
if( empty($image_size_info) ) $mime_type = "";
else $mime_type = @image_type_to_mime_type( $image_size_info[2] );

//safety for all cases:
if( empty($mime_type) ) $mime_type = "";

if(  strpos($mime_type, "image/") === false  )
{
//not an Image !
} 
else 
{
  //proceed file upload
}

If above code doen't work then it might help you -->> https://github.com/thephpleague/flysystem/commit/0ec96b1104e57bfcf0e40d6169c8e203b7942b34




回答4:


If you have cpanel just go to

Select PHP Version

and search for the extension

fileinfo

check it and you're good to go.




回答5:


<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    # Redirect Trailing Slashes...
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]

<IfModule mod_suphp.c>
suPHP_ConfigPath /home/username/public_html/subfolder
</IfModule>

</IfModule>
subfolder is the laravel project where I want to serve my application.

php.ini file in my subfolder's root folder & for enable PHPFileinfo I write those code in php.ini file

extension=fileinfo.so
extension=pdo.so
extension=pdo_mysql.so



回答6:


If you are using WHM, go to Easy Apache, search fileinfo (In the search field), and enable it ( I found for php5.5, php5.6 and php.7.0.

And click on "Review" left tab.

Then click on provision, and done. It works for me ( I spend 3 hours trying install/enable fileinfo)



来源:https://stackoverflow.com/questions/28981576/how-to-enable-php-fileinfo-extension-in-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!