简体   繁体   English

PHP FileInfo扩展名php.ini覆盖

[英]PHP FileInfo Extension php.ini override

I'm making use of a GD Library on my application which requires me to modify my php.ini to work. 我在应用程序上使用了GD库,这需要我修改php.ini才能正常工作。 I understand if I uncomment to extension=fileinfo.so the application will work as required, but my challenge is that I don't have access to my shared host server configurations. 我知道如果我不注释extension=fileinfo.so那么该应用程序将按要求运行,但是我面临的挑战是我无法访问共享的主机服务器配置。 My question, Is there a way around using ini_set('', '') 我的问题是,有没有办法使用ini_set('', '')

Thanks ahead 提前谢谢

Shared hosting has disabled ini_set() function for security reason if the hosting provider turn on ini_set() to you, you can have full access to php variable control, which the hosting provider don't want 出于安全原因,如果托管提供程序为您打开了ini_set() ,则共享托管已禁用ini_set()函数,您可以完全访问php变量控制,而托管提供程序则不需要

for your purpose, you can do it through .htaccess file within your application root folder 为此,您可以通过应用程序根文件夹中的.htaccess文件来完成此操作

two directives are permitted using .htaccess 使用.htaccess允许两个指令

php_flag <boolean-flag-name> on|off
php_value <flag-name> <flag-value>

php_flag should be used for on/off values php_flag应该用于开/关值

For example, the following .htaccess file will disable globals, set the maximum file upload size to 20MB, and allow PHP scripts to run for 10 minutes (600 seconds): 例如,以下.htaccess文件将禁用全局变量,将最大文件上传大小设置为20MB,并允许PHP脚本运行10分钟(600秒):

php_flag register_globals off
php_value upload_max_filesize 20M
php_value max_execution_time 600

You can also use ini_set function. 您也可以使用ini_set函数。 in php scripts which allows you to change a setting within your application at runtime. 在php脚本中,它允许您在运行时更改应用程序中的设置。 The function accepts two arguments: 该函数接受两个参数:

ini_set(flag-name, flag-value), ini_set(标志名,标志值),

Example

<?php
ini_set('register_globals', 0);
ini_set('upload_max_filesize', '20M');
ini_set('max_execution_time', 600);
?>

We can query the php interpreter before changing these value to query, we can use ini_get() method 我们可以在更改这些值以进行查询之前查询php解释器,我们可以使用ini_get()方法

ini_get(flag-name) Returns the configuration value. ini_get(flag-name)返回配置值。 I'd recommend checking your configuration change and taking appropriate action. 我建议检查您的配置更改并采取适当的措施。 Don't assume ini_get() will always work. 不要以为ini_get()会一直工作。

ini_get_all([extension]) Returns all configuration values as an associative array. ini_get_all([extension])以关联数组的形式返回所有配置值。 The optional extension parameter returns options specific to that extension, eg 'allow_url_fopen'. 可选的扩展名参数返回特定于该扩展名的选项,例如“ allow_url_fopen”。

get_cfg_var(flag-name) Returns the original configuration value from php.ini (not any overrides set in .htaccess or by ini_set). get_cfg_var(flag-name)从php.ini返回原始配置值(没有任何在.htaccess或ini_set中设置的替代值)。

ini_restore(flag-name) Returns a configuration option to its original value. ini_restore(flag-name)将配置选项返回其原始值。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM