6

I'm setting the upload max filesize in my form:

$file = new Zend_Form_Element_File('file');
$file->setLabel('File to upload:')
    ->setRequired(true)
    ->addValidator('NotEmpty')
    ->addValidator('Count', false, 1)
    ->addValidator('Size', false, 10485760) //10MB = 10,485,760 bytes
    ->setMaxFileSize(10485760)
    ->setDestination(APPLICATION_UPLOADS_DIR);
$this->addElement($file);

But I'm getting this error message in my Zend Framework application:

Notice: Your 'upload_max_filesize' config setting limits the maximum filesize to '2097152'. You tried to set '10485760' in /location/to/Zend/Form/Element/File.php on line 620

What am I doing wrong?

Andrew
  • 227,796
  • 193
  • 515
  • 708

4 Answers4

13

The upload_max_filesize is an option in the configuration of PHP itself, and independant of Zend Framework.

If you need to modify that max upload size, you should set it in your php.ini file -- note you'll certainly also have to modify post_max_size.

Pascal MARTIN
  • 395,085
  • 80
  • 655
  • 663
  • I'm trying to set these in my application.ini file as phpSettings.post_max_size but it doesn't seem to be working, is there another way I can set this? Like some sort of function? set_post_max_size() if such a function exists? – Andrew Dec 10 '09 at 20:11
  • Not sure this can be configured from the PHP code, actually, as dealing with the uploaded data/file is done by Apache+PHP before your script even really starts... – Pascal MARTIN Dec 10 '09 at 20:18
  • I believe you can configure from PHP code, ini_set('post_max_size', 10485760); – Jay Zeng Dec 11 '09 at 00:16
  • I wasn't able to get this to work: ini_set('post_max_size', 10485760); – Andrew Dec 15 '09 at 02:38
5

I know this was asked a while ago, but the answer is still relevant, and not actually in this message.

The original poster noted:

Notice: Your 'upload_max_filesize' config setting limits the maximum filesize to '2097152'. You tried to set '10485760' in /location/to/Zend/Form/Element/File.php on line 620

and in a further note:

I wasn't able to get this to work: ini_set('post_max_size', 10485760)

Technically the class method setMaxFileSize(), is doing the same thing as that ini_set.

What's largely undocumented, but applies here is that you're allowed to modify this value to anything you want that doesn't exceed the value in the php.ini that is read on startup.

For example, the *nix the default value is 2M. If you haven't modified the php.ini, you'll only be able to overwrite this value with a number from 0 to 2097152.

One last note. As mentioned in Pascal MARTIN 's post, it's mentioned that upload_max_filesize and post_max_size go somewhat hand in hand. Something else to consider is that if you're making these values a somewhat large number, you'll probably want to make sure that your memory_limit value is also considered as you're script will fail due to a memory exhaustion.

conrad10781
  • 2,223
  • 19
  • 17
  • Thanks for the part about not exceeding the value defined in php.ini... you're right, it's not documented at all and it made me waste lot of time! =/ – MDT Feb 17 '14 at 01:33
1

By default upload_max_filesize is 2MB in php settings, which is independent of max file size in your upload method. You can increase upload_max_filesize in php.ini file.

Or You can also change it in your project .htaccess file in that way changes are for that project only. For example :-

php_value upload_max_filesize 20M
php_value post_max_size 25M
php_value memory_limit 100M

But Keep post_max_size more than upload_max_filesize and memory_limit should be more than post_max_size.

vj01
  • 111
  • 1
  • 2
  • 7
-2

Have you overwritten the default max size in php.ini?

Jay Zeng
  • 1,423
  • 10
  • 10