This post describes how to configure upload_max_filesize
and post_max_size
at application level, instead of setting them in php.ini.
IMHO, php.ini is for setting basic configuration across all applications. It should be "low spec", just enough for most applications. This is to prevent unintentional "abuse" from applications using large among of resources (e.g. execution time, memory limit, upload file size limit). Supposed default upload_max_filesize
in php.ini is 2MB, and a particular applications requries upper limit of 20MB. I prefer to set it at application-level, instead of php.ini. I dont want other applications to easily upload big files.
There are few ways to overwrite default PHP configurations. For most configurations, can be used to overwrite configuration at runtime.
Determine when and where a PHP directive may or may not be setReferring to List of php.ini directives, ini_set()
does not work for all configurations. upload_max_filesize
and post_max_size
are classified as PHP_INI_PERDIR. Meaning they can only be set in php.ini, .htaccess, httpd.conf or .user.ini. Since I am using Apache web server, I set them in .htaccess.
For a quick guide on how to set PHP configuration, please refer to Set php.ini Values Using .htaccess by David Walsh.