简体   繁体   English

如何在 PHP 中启用 php_fileinfo 扩展?

[英]How to enable php_fileinfo extension in PHP?

My Laravel app can't validate uploaded images.我的 Laravel 应用无法验证上传的图片。 It returns this error message:它返回此错误消息:

Unable to guess the mime type as no guessers are available (Did you enable the php_fileinfo extension?)无法猜测 mime 类型,因为没有可用的猜测器(您是否启用了 php_fileinfo 扩展?)

Laravel 错误信息

I know enabling php_fileinfo.dll/php_fileinfo.so at php.ini fixes it.我知道在 php.ini 启用 php_fileinfo.dll/php_fileinfo.so 可以修复它。 But I don't have access to my remote server's php.ini file.但我无权访问远程服务器的 php.ini 文件。

So I thought is there any other way to enable it?所以我想还有其他方法可以启用它吗? And how?如何? Maybe I can use PHP's ini_set() methods?也许我可以使用 PHP 的ini_set()方法? 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.我还读到您可以使用 .htaccess 文件覆盖 php.ini 设置。 But how?但是如何?

As Laravel's default, my .htaccess file is:作为 Laravel 的默认值,我的 .htaccess 文件是:

<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?你应该如何把这些额外的东西放在那里?

create own php.ini file in root folder of your directory.在您目录的根文件夹中创建自己的php.ini文件。

example if you are making changes on a server then it should be inside the public.html folder.例如,如果您在服务器上进行更改,那么它应该位于 public.html 文件夹中。

create file name php.ini it will override the settings.创建文件名 php.ini 它将覆盖设置。 just add in the file只需在文件中添加

extension=php_fileinfo.dll

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 .如果您正在使用 WHM,请转到 Easy Apache,搜索文件信息(在搜索字段中)并启用它(我找到了php5.5php5.6php.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)它对我有用(我花了 3 个小时尝试安装/启用文件信息)

Create a .htaccess file where your root is and then do this在您的根所在的位置创建一个.htaccess文件,然后执行此操作

php_value extension=php_fileinfo.dll

or或者

php_admin_flag extension=php_fileinfo.dll

If you have cpanel just go to如果你有 cpanel 就去

Select PHP Version选择 PHP 版本

and search for the extension并搜索扩展名

fileinfo档案信息

check it and you're good to go.检查它,你很高兴去。

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如果上面的代码不起作用,那么它可能会帮助你 -->> https://github.com/thephpleague/flysystem/commit/0ec96b1104e57bfcf0e40d6169c8e203b7942b34

<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

Go to WHM and search Easy Apache install the mentioned Profile on the WHM it resolves the issue.转到 WHM 并搜索 Easy Apache 在 WHM 上安装提到的配置文件,它解决了问题。

WHM 截图

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 启用 php_fileinfo 扩展? - Enable the php_fileinfo extension? 您是否在Azure中启用了php_fileinfo扩展 - Did you enable the php_fileinfo extension in Azure 编译php后如何重新启用php_fileinfo扩展名 - how to reenable php_fileinfo extension after compile php php_fileinfo扩展名不适用于laravel 4在线 - php_fileinfo extension not working for laravel 4 in online Laravel“启用fileinfo扩展名后,由于没有可用的猜测器,因此无法猜测mime类型(是否启用了php_fileinfo扩展名?)” - Laravel “Unable to guess the mime type as no guessers are available (Did you enable the php_fileinfo extension?)” when fileinfo extension is enabled 1/1)LogicException由于没有可用的猜测器,因此无法猜测mime类型(是否启用了php_fileinfo扩展名?) - 1/1) LogicException Unable to guess the mime type as no guessers are available (Did you enable the php_fileinfo extension?) 如何在 Windows 10 中的 php.ini 中安装扩展 php_fileinfo - How can I install extension php_fileinfo in my php.ini in Windows 10 Laravel文件下载 - 未启用php_fileinfo扩展 - Laravel file download - php_fileinfo extension not enabled 我如何启用 php fileinfo 扩展 - how do i enable php fileinfo extension .htaccess启用php fileinfo扩展 - .htaccess enable php fileinfo extension
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM