I was working for a Drupal website which i wanted to increase its maximum file upload size. This value is determined by the php.ini configuration file.
Unfortunately, the server hosting does not provide the SSH access so i can’t edit the php.ini. Therefore i have to let Drupal override the php.ini settings. There is 2 ways for Drupal to override the php.ini settings.
- <drupal_root>/sites/default/settings.php
- <drupal_root>/.htaccess
Let’s take a look on the settings.php first.
...
/**
* PHP settings:
*
* To see what PHP settings are possible, including whether they can
* be set at runtime (ie., when ini_set() occurs), read the PHP
* documentation at http://www.php.net/manual/en/ini.php#ini.list
* and take a look at the .htaccess file to see which non-runtime
* settings are used there. Settings defined here should not be
* duplicated there so as to avoid conflict issues.
*/
ini_set('arg_separator.output', '&');
ini_set('magic_quotes_runtime', 0);
ini_set('magic_quotes_sybase', 0);
ini_set('session.cache_expire', 200000);
ini_set('session.cache_limiter', 'none');
ini_set('session.cookie_lifetime', 2000000);
ini_set('session.gc_maxlifetime', 200000);
ini_set('session.save_handler', 'user');
ini_set('session.use_cookies', 1);
ini_set('session.use_only_cookies', 1);
ini_set('session.use_trans_sid', 0);
ini_set('url_rewriter.tags', '');
...
You can make use of the ini_set() function to change the php.ini settings. But according the List of php.ini directives, upload_max_filesize could not be set through ini_set().
Therefore, i have to change the upload_max_filesize value by the second approach which is editing the .htaccess file. Open the <drupal_root>/.htaccess and add the upload_max_filesize and post_max_size as follow.
... # PHP 5, Apache 1 and 2. <IfModule mod_php5.c> php_value magic_quotes_gpc 0 php_value register_globals 0 php_value session.auto_start 0 php_value mbstring.http_input pass php_value mbstring.http_output pass php_value mbstring.encoding_translation 0 # Add you own configuration here php_value upload_max_filesize 10M php_value post_max_size 10M </IfModule> ...
The .htaccess will take effect immediately. Now the file upload size limit could be set to 10M.
Done =)
Reference:

I am using Yahoo web hosting, which apparently doesn’t allow the uploading or usage of a .htaccess file – what do I do now?! I am about to kill something.
LikeLike
so u could override the PHP settings by /sites/default/settings.php. it does not work?
LikeLike
Thanks for making my life a little simpler.
LikeLike
You are welcome. =)
LikeLike
Thank god.
i have all abilities to change everithing but nothing worked except what you suggesed.
Thanks my man!
LikeLike
You are welcome. =)
LikeLike