如何从 php 代码更改 php 设置?

发布于 2024-09-01 06:02:12 字数 148 浏览 2 评论 0 原文

我想更改 php 设置,但从“.php”页面而不是 php.ini 更改。我要更改的设置是

upload_max_filesizepost_max_sizememory_limit

I want to change the php setting but from ".php" page not php.ini. The settings I want to change is

upload_max_filesize, post_max_size and memory_limit

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

一梦浮鱼 2024-09-08 06:02:12

如果您有AllowOverride 选项,您可以尝试使用 .htaccess 文件:

将名为 .htaccess 的文件放置到您的 webroot 中:

php_value upload_max_filesize 10000
php_value post_max_size 10000
php_value memory_limit 10000

You can try it with a .htaccess file, if you have AllowOverride Options:

Place a file named .htaccess to your webroot:

php_value upload_max_filesize 10000
php_value post_max_size 10000
php_value memory_limit 10000
不念旧人 2024-09-08 06:02:12

唯一可以在 PHP 中更改的是最后一个,可以使用 ini_set 进行更改,例如this:

ini_set('memory_limit', '32M');

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:

ini_set('memory_limit', '32M');

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.

小苏打饼 2024-09-08 06:02:12

如果您的服务器管理员没有阻止,您可以使用 ini_set() 更改内存限制:

ini_set("memory_limit","16000000"); // abbreviations like "16M" work only 
                                    // in php.ini, always use full numbers here

在加载 PHP 脚本之前需要另外两个选项,无法在 php.ini 中更改这些选项。

If your server administrator hasn't prevented it, you can use ini_set() to change the memory limit:

ini_set("memory_limit","16000000"); // abbreviations like "16M" work only 
                                    // in php.ini, always use full numbers here

The two other options are needed before the PHP script is loaded, there is no way to change those in php.ini.

烧了回忆取暖 2024-09-08 06:02:12

使用

ini_set ('key', 'value');

请注意,并非所有可用选项都可以使用 ini_set() 进行更改。这是一个列表:ini.list

阅读ini_set 参考;

Use

ini_set ('key', 'value');

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;

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文