在服务器上覆盖 php.ini

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8812154/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 05:33:46  来源:igfitidea点击:

Overriding php.ini on server

.htaccessphpexecution-time

提问by Tom

I have a page which allows users to upload images.

我有一个允许用户上传图片的页面。

It is returning a 500 error when the user tries to upload larger images though.

但是,当用户尝试上传更大的图像时,它会返回 500 错误。

The following code...

下面的代码...

<?php echo ini_get("upload_max_filesize"); 
echo ini_get("post_max_size"); 
echo ini_get("max_input_time");
echo ini_get("max_execution_time");
?>

...returns:

...返回:

100M
100M
60
3600

I'm guessing from this that it's the max-input-time that's causing the problem as i've tested with files under 100mb but taking longer than 60 seconds to upload.

我从中猜测,这是导致问题的最大输入时间,因为我已经对 100mb 以下的文件进行了测试,但上传时间超过 60 秒。

I don't have access with my host to the php.ini file, so can I override these settings? I've tried adding an htaccess file but I'm not sure I've put it in the correct place.

我的主机无法访问 php.ini 文件,所以我可以覆盖这些设置吗?我试过添加一个 htaccess 文件,但我不确定我是否把它放在了正确的地方。

回答by Aleksandar Vucetic

Put a .htaccess file in the root folder of your website (where your php script is) and add the following values:

将 .htaccess 文件放在您网站的根文件夹(您的 php 脚本所在的位置)并添加以下值:

php_value upload_max_filesize 100M
php_value post_max_size 100M
php_value max_execution_time 200
php_value max_input_time 200

Of course, you can put other size and time limits. That should work.

当然,您可以设置其他大小和时间限制。那应该工作。

回答by TerryE

Setting up php ini directives depends on the nature of your service provider's configuration. Run a phpinfo()script to look at your configuration. If your provider is starting PHP using suPHP in a user UID context then it may look for a php.ini in the script's directory. Thisis how it works for my hosting provider.

设置 php ini 指令取决于您的服务提供商配置的性质。运行phpinfo()脚本以查看您的配置。如果您的提供者在用户 UID 上下文中使用 suPHP 启动 PHP,那么它可能会在脚本目录中查找 php.ini。 就是我的托管服务提供商的工作方式。