仅针对特定 PHP 文件增加 "post_max_size" 和 "upload_max_filesize",而不是针对整个服务器

Increase "post_max_size" and "upload_max_filesize" only for a specific PHP file, and not for the whole server

我知道,如 中所述,如何在 php.ini 中增加这些值:

upload_max_filesize = 50M 
post_max_size = 50M 

但是,如何仅对一个站点/一个 .php 脚本启用此类设置,而不是对同一 Apache 服务器托管的所有 PHP 站点全局启用此类设置?

有没有办法把这是一个本地配置,比如.htaccess,而不是全局配置?

看看 directives page,有一列 "Changeable"。这显示了如何更改每个设置,例如仅在 php.ini 中,或使用 .htaccess 或 ini_set 等

每种可能模式的解释是here

对于upload_max_filesizepost_max_size,模式都是PHP_INI_PERDIR

Entry can be set in php.ini, .htaccess, httpd.conf or .user.ini (since PHP 5.3)

所以是的,您可以将 .htaccess 文件中的条目用于:

php_value upload_max_filesize 50M
php_value post_max_size 50M