[英]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 扩展?)
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.5
、 php5.6
和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)
它对我有用(我花了 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 上安装提到的配置文件,它解决了问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.