Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zend File upload: File exceeds the defined ini size

Inside my form i define this file upload field:

$this->setEnctype(Zend_Form::ENCTYPE_MULTIPART);

$logo = $this->createElement('file', 'logo');
$logo->setLabel('Group logo')
     ->setMaxFileSize(5242880) // 5mb
     ->addValidator('IsImage')
     ->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 :/

like image 292
oli Avatar asked Jun 23 '11 07:06

oli


People also ask

How to fix “the uploaded file exceeds the upload_max_filesize directive?

That means if you try to upload a file larger than that limit, you’re going to see the “the uploaded file exceeds the upload_max_filesize directive in php.ini”, or a similar message like “ file_name exceeds the maximum upload size for this site .” In order to fix this error, you need to increase the file size upload limit.

Which class is used for file uploading in Zend?

Another class used in file uploading is Zend\Filter\File\RenameUpload. The RenameUpload is used to move the uploaded file to our desired location. The partial class to use file filter is as follows −

What is upload_max_filesize in PHP?

This maximum, in megabytes, is defined in the upload_max_filesize directive. The upload_max_filesize directive itself is located in the php.ini file, which is the default server configuration file for applications that require PHP. Those two things – upload_max_filesize and php.ini – are what the error message you see is referencing.

How do I fix a file size upload error in PHP?

In order to fix this error, you need to increase the file size upload limit. That is, you need to increase the value of the upload_max_filesize directive in your php.ini file. There are several different ways you can do this – the exact method that you choose will depend on your preference and your host’s configuration.


1 Answers

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

like image 128
Alex Pliutau Avatar answered Nov 08 '22 16:11

Alex Pliutau