Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm trying to write a plugin script that involves the user uploading a large file. To cope with this I need to alter the following settings:

  • post_max_size
  • upload_max_size

If I alter these in php.ini it works as intended. However, it I try the following from within my plugin code, it doesn't take affect:

@ini_set( 'upload_max_size' , '100M' );
@ini_set( 'post_max_size', '105M');

I don't really want to have to talk the user through editing of either php.ini or a WordPress config file. Ideally I'd be able to perform it for them from within the plugin.

Does anyone know how this can be achieved?

Cheers.

share|improve this question
add comment

1 Answer

First, the setting you want is 'upload_max_filesize', not 'upload_max_size'. Second, both of those settings are PHP_INI_PERDIR, which means they can only be set with php.ini, .htaccess, or httpd.conf. For more information see the PHP documentation on php.ini directives and their configuration.

I would suggest using .htaccess, personally. You might look into writing the information directly to the file from the script, just like WordPress attempts to do for rewrite rules.

EDIT

I just realized that I told you to do it in .htaccess but didn't tell you how. To set those values in .htaccess add the following lines to the file (anywhere in the file):

php_value upload_max_filesize 100M
php_value post_max_size 105M
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.