我如何检查 ini_set 是否可以在服务器上工作?
设置如下选项
ini_set('upload_max_filesize', '8M');
我如何检查服务器配置是否允许我在 PHP 脚本中 ?这是 php.ini 指令 的列表,但我真的不知道如何制作在尝试更改该值之前进行检查。
How can i check if server configuration allows me to set an option like:
ini_set('upload_max_filesize', '8M');
in a PHP script? Here is a list of php.ini directives but i can't really figure out how to make a check before tring to change that value.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
检查我是否可以对某些
选项
使用ini_set
,如何?ini_set
将返回旧的成功时值为,失败时为false
*。有了这些知识,您可以编写一条语句来检查您的呼叫是否成功,如下所示。(*):请注意 PHP 5.3.0 中的返回值从
''
(空字符串)更改为false
。因此,您还需要检查当前的 PHP 版本。另一种方法是使用
ini_get_all
< /a> 将为您提供有关每个可用选项的详细信息,它是 使用权级别。我想禁用某些选项的
ini_set
,如何操作?有几种方法可以使选项在运行时不可更改(以禁用
ini_set
的方式),其中包括以下两种方法,您可以在提供的链接中阅读更多信息。示例(取自此文档)
Check if I'm allowed to use
ini_set
for someoption
, how?ini_set
will return the old value on success, andfalse
* on failure. With this knowledge you can write a statement checking if your call went through, like the below.(*): Note the return value changed in PHP 5.3.0 from
''
(an empty string) tofalse
. So you need to check your current PHP version as well.Another method is to use
ini_get_all
which will provide you with details regarding every option available, and it's access level.I'd like to disable the use of
ini_set
for some option(s), how?There are a few methods of making options unchangeable runtime (in a way disabling
ini_set
), among them are the following two which you can read more about at the provided link.Example (taken from this documentation)
除非您尝试设置所需的值,否则不可能知道您的真正限制是多少。例如,可能安装了 suhosin 补丁,这可能会阻止您更改以下值全部。
因此,检查是否可行的唯一选择是尝试并检查返回值(在任何情况下都应该这样做):
It is impossible to know what your real limit is unless you try to set the desired value. There might be the suhosin patch installed, for example, which could prevent you from changing the value at all.
So your only option for checking if it is possible is to try it and check the return value (which you should to in any case):