Zend File upload: File exceeds the defined ini size
Asked Answered
M

8

16

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 :/

Markusmarl answered 23/6, 2011 at 7:12 Comment(0)
C
14

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

Caritacaritas answered 23/6, 2011 at 7:32 Comment(3)
I added $this->setEnctype(Zend_Form::ENCTYPE_MULTIPART); (see my first post), in the html source that translates to: <form enctype="multipart/form-data" method="post" action=""> (thats whats actually in the source, so that shouldnt be the problem either)Markusmarl
This answer solved it for me. I forgot to add enctype="multipart/form-data" and when I did, the file element started acting normally.Rica
Thank you very much, I always have to forgot about that ;)Callicrates
I
6

Add

enctype="multipart/form-data"

to your <form> element. Solved my problem.

Incandescent answered 31/5, 2013 at 20:32 Comment(0)
R
3

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"); ?>">

Ragsdale answered 1/4, 2013 at 7:40 Comment(0)
C
3

Please check your php.ini file and increase upload_max_filesize. By default, it is 2M (2 MegaBytes). Also in order to be able to post file with size more than 2M you need to update value of post_max_size

Circe answered 19/1, 2018 at 5:47 Comment(0)
R
2

Chances are that the php extension fileinfo is not activated.

Remuneration answered 15/3, 2012 at 15:18 Comment(0)
C
1

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.

Caritacaritas answered 23/6, 2011 at 7:26 Comment(2)
Just tried it, doesn't get it done. And its not the current validators triggering the message, as i said i tried removing all of them and the problem remainsMarkusmarl
Yes. Sorry. See my another answer.Caritacaritas
A
1

It looks like you're missing the destination:

$logo->setLabel('Group logo')
     ->setDestination('/var/www/upload')
     ...

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

Alkalify answered 23/6, 2011 at 7:29 Comment(4)
Hm, interesting. I just added it and now nothing happens - the validation on the upload fails, but without an error message. I set it to a directory that is chmodded to 777 (with absolute path) so that shouldnt be an issue.Markusmarl
@skooli - You should try adding ini_set('display_errors', true); and error_reporting(E_ALL); in your file just in case errors are suppressed. There may be something else failing.Alkalify
it's already set to E_ALL but there are no errors when I submit filesMarkusmarl
NOTE: ->setDestination('/var/www/upload') is deprecated, use ->addFilter('Rename', '/new/destination/path') insteadLulita
F
1

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

->setDestination($this->_config->folder->ugc);
->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.

Fezzan answered 26/9, 2012 at 16:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.