如何从 php 代码更改 php 设置?
我想更改 php 设置,但从“.php”页面而不是 php.ini 更改。我要更改的设置是
upload_max_filesize
、post_max_size
和 memory_limit
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
我想更改 php 设置,但从“.php”页面而不是 php.ini 更改。我要更改的设置是
upload_max_filesize
、post_max_size
和 memory_limit
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(4)
如果您有AllowOverride 选项,您可以尝试使用 .htaccess 文件:
将名为 .htaccess 的文件放置到您的 webroot 中:
You can try it with a .htaccess file, if you have AllowOverride Options:
Place a file named .htaccess to your webroot:
唯一可以在 PHP 中更改的是最后一个,可以使用 ini_set 进行更改,例如this:
PHP 总是在 PHP 脚本启动之前处理客户端请求。这意味着在脚本启动之前,上传的文件已经上传,并且发布的表单已经完全发布。因此,上传和发布设置不能在脚本中设置,因为在 PHP 脚本启动时它们已经不相关了。
The only one of those that can be changed from within PHP is the last one, which can be changed with ini_set like this:
PHP always processes the client request before the PHP script is started. This means that uploaded files are already uploaded and posted forms are already fully posted beforeb he script starts. The upload and post settings can therefore not be set in the script, ebcause they are already irrelevant when the PHP script is started.
如果您的服务器管理员没有阻止,您可以使用
ini_set()
更改内存限制:在加载 PHP 脚本之前需要另外两个选项,无法在 php.ini 中更改这些选项。
If your server administrator hasn't prevented it, you can use
ini_set()
to change the memory limit:The two other options are needed before the PHP script is loaded, there is no way to change those in php.ini.
使用
请注意,并非所有可用选项都可以使用 ini_set() 进行更改。这是一个列表:ini.list
阅读ini_set 参考;
Use
Note that not all the available options can be changed using ini_set(). Here'is a list: ini.list
Read more in ini_set reference;