PHP, Zend Framework: How to set the upload max filesize?
Asked Answered
V

4

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?

V1 answered 10/12, 2009 at 19:57 Comment(0)
E
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.

Ecto answered 10/12, 2009 at 20:4 Comment(4)
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?V1
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...Ecto
I believe you can configure from PHP code, ini_set('post_max_size', 10485760);Cool
I wasn't able to get this to work: ini_set('post_max_size', 10485760);V1
S
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.

Soler answered 8/5, 2012 at 12:43 Comment(1)
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! =/Dipetalous
C
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.

Chindwin answered 21/3, 2016 at 6:17 Comment(0)
C
-2

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

Cool answered 10/12, 2009 at 20:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.