Zend File upload: File exceeds the defined ini size

Inside my form i define this file upload field:


$logo = $this->createElement('file', 'logo');
$logo->setLabel('Group logo')
     ->setMaxFileSize(5242880) // 5mb
     ->addValidator('Count', false, 1)
     ->addValidator('Size', false, 5242880)
     ->addValidator('Extension', false, array('jpg', 'jpeg', 'png', 'gif'));

However, no matter how small files I upload I get this error: File 'logo' exceeds the defined ini size.

The error message seemed pretty straight forward so I checked the php config (phpinfo() on the same exact page that handles the form)

  • file_uploads: On
  • upload_max_filesize: 2000M
  • memory_limit: 128M
  • post_max_size: 8M

While those values don't exactly make sense, they absolutely should allow me to upload files up to 8Mb but the upload always failes with the message from above. Even files smaller than 1Kb fail. I also tried removing all setters/validators but it still fails.

While searching for an answer I came across some posts that said that it was ajax' fault but this is a regular form, so now I'm stuck.

Update: I'm terribly sorry to have wasted your time, there was another unclosed form on the page which voided the multipart-declaration. Could have found that out sooner if I had tested with larger files rather than small ones :/


Add enctype="multipart/form-data" in your form. It should solve your problem.



to your <form> element. Solved my problem.

Chances are that the php extension fileinfo is not activated.

if you are using script file to render your file , you need to retrieve the enctype info that you specified in form class from your script file. <form enctype="<?php echo $this->element->getAttrib("enctype"); ?>">

It looks like you're missing the destination:

$logo->setLabel('Group logo')

You might want to make sure that the folder is writeable by your web server.

When I commented out the following I got the same error:

->addValidator(Kvadrat_Form_Element_File::VALIDATE_COUNT, true, 1);
->addValidator(Kvadrat_Form_Element_File::VALIDATE_SIZE, true, 5 * 102400);

(I commented it out as was doing the file uploads separately with FormData)

So I uncommented it and it all worked again.

Your size validator is incorrect. You should use this format:

->addValidator('Size', false, array('max' => '5242880'))

Your validator checks file's size == 5242880, NOT <= 5242880.

Need Your Help

How to use Eval in codebehind to set Page.Title

asp.net vb.net data-binding eval page-title

I have a SQLDataSource that is bound to a ListView control but I want to place parts of the bound record into the HTML TITLE attribute. Here is my codebehind file that I want to change so it can us...

NSMutableDictionary and values

objective-c cocoa-touch nsdictionary nsnull

Ok. I've searched and searched to no avail and I keep beating my head over this.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.