Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 647
Andrew Avatar asked Dec 10 '09 19:12

Andrew


People also ask

How do I increase my max upload size at runtime?

To increaes file upload size in PHP, you need to modify the upload_max_filesize and post_max_size variable's in your php. ini file. In addition, you can also set the maximum number of files allowed to be uploaded simultaneously, in a single request, using the max_file_uploads .

What is PHP Postmax size?

The default PHP values are 2 MB for upload_max_filesize, and 8 MB for post_max_size. Depending on your host, changing these two PHP variables can be done in a number of places with the most likely being php. ini or . htaccess (depending on your hosting situation).


2 Answers

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.

like image 87
Pascal MARTIN Avatar answered Oct 09 '22 10:10

Pascal MARTIN


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.

like image 42
conrad10781 Avatar answered Oct 09 '22 11:10

conrad10781