laravel 如何在 PHP 中启用 php_fileinfo 扩展?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28981576/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to enable php_fileinfo extension in PHP?
提问by doncadavona
My Laravel app can't validate uploaded images. It returns this error message:
我的 Laravel 应用无法验证上传的图片。它返回此错误消息:
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. But I don't have access to my remoteserver's php.ini file.
我知道在 php.ini 启用 php_fileinfo.dll/php_fileinfo.so 可以修复它。但我无权访问远程服务器的 php.ini 文件。
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:
所以我想还有其他方法可以启用它吗?如何?也许我可以使用 PHP 的ini_set()
方法?我尝试使用它,例如:
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?
我还读到您可以使用 .htaccess 文件覆盖 php.ini 设置。但是如何?
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 ^(.*)/$ / [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?
你应该如何把这些额外的东西放在那里?
回答by Sulthan Allaudeen
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
回答by Sayed Mohd Ali
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. just add in the file
创建文件名 php.ini 它将覆盖设置。只需在文件中添加
extension=php_fileinfo.dll
回答by ungalcrys
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.
检查它,你很高兴去。
回答by Vishwas Soni
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