PHP, Zend Framework: how to set the maximum upload file size?

I set the upload max file size 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 get 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?

+6
php zend-framework zend-file
source share
4 answers

upload_max_filesize is an option in the configuration of PHP itself and independent of the Zend Framework.

If you need to change this maximum upload size, you must install it in your php.ini - note that you will also need to change post_max_size .

+12
source share

I know this was asked some time ago, but the answer is still relevant, and not actually in this post.

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 the following note:

I failed to get this to work: ini_set ('post_max_size', 10485760)

Technically, the setMaxFileSize () class method does the same as ini_set.

Which is mostly undocumented, but it applies that you can change this value to whatever you want, which does not exceed the value in php.ini that is read at startup.

For example, * nix defaults to 2M. If you have not changed php.ini, you can only overwrite this value with a number from 0 to 2097152.

One last note. As mentioned in a Pascal MARTIN post, he mentioned that upload_max_filesize and post_max_size go hand in hand. Something else to consider is that if you make these values ​​a little larger, you probably want to make sure that your memory_limit value is also considered, since you script will crash due to memory exhaustion.

+5
source share

By default, upload_max_filesize is 2 MB in php settings, which does not depend on the maximum file size in your upload method. You can increase upload_max_filesize in php.ini file.

Or you can also change it in the project's .htaccess file so that the changes are only for that project. For example: -

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

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

+1
source share

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

-2
source share