Hmm... you seem to be right. It looks as if there's no file submitted. This is what is in the $_FILES array on a successful file upload (file less than php.ini's max file-size): Array ( [file1] => Array ( [name] => testfile.pdf [type] => application/pdf [tmp_name] => /private/var/tmp/phpPuRUtw [error] => 0 [size] => 112947 ) )
If I upload a file larger than what's definined in php.ini the array is empty. The print_r function just outputs: Array() thomasW wrote: > > That's correct. MAX_FILE_SIZE is a hidden form field. > > It would be interesting to see what your server saves as data to the > $_FILES > array. > Normally there should be an error (3 or 4) but it seems that in your case > there is no file submitted in this case. > > Greetings > Thomas Weidner, I18N Team Leader, Zend Framework > http://www.thomasweidner.com > > ----- Original Message ----- > From: "bytte" <[email protected]> > To: <[email protected]> > Sent: Wednesday, February 18, 2009 1:03 AM > Subject: Re: [fw-general] User uploads file bigger than what's allowed in > php.ini, can it be caught? > > >> >> It's really weird. Since I'm using the code from the svn trunk it doesn't >> output the MAX_FILE_SIZE in the html code no more. It does show it in the >> first form on the same page. >> >> All my error messages display fine. But still no error message when the >> user >> uploads a file bigger than what's allowed in php.ini >> >> Here the code in my controller: >> >> public function editAction() >> { >> >> $toestellen = new Toestellen(); >> //fetch het toestel met deze id >> $row = $toestellen->fetchRow('id=' . $this->id); >> $this->view->toestel = $row; >> $this->view->title = 'Wijzig ' . $row->naam; >> if($row->type == 2) { >> $form = new OmgevingForm(); >> } else { >> $form = new ToestelForm(); >> } >> $form->submit->setLabel('Wijzig'); >> $form->submit->setDescription('of "' . $this- view->baseUrl() . >> '/speelpleinen/toestel/id/' . $this->id . >> '/speelplein/'.$this->speelpleinId >> . '">Annuleer '); >> $this->view->form = $form; >> >> //maak bestandenform >> $bestandenForm = new BestandenForm(); >> $this->view->bestandenForm = $bestandenForm; >> >> //toon gekoppelde bestanden >> $bestanden = new Bestanden(); >> $bestandenLijst = >> $bestanden->fetchAll($bestanden->select()->where('ref_tabel = >> ?','toestellen')->where('ref_id = ?',$this->id)->order('created_dt >> ASC')); >> $this->view->bestandenLijst = $bestandenLijst; >> >> if($this->flash->hasMessages()) { >> $this->view->formResponse = implode("<br />", >> $this->flash->getMessages()); >> } >> if($this->_request->isPost()) { >> $formData = $this->_request->getPost(); >> if(array_key_exists('pic1',$formData)) { //het gaat om het toestelform >> if($form->isValid($formData)) { >> if ($_FILES['pic1']['tmp_name']) { >> $formData['pic1'] = $_FILES['pic1']; >> } >> if($row->type == 2) { >> $omgevingen = new Omgevingen(); >> $omgevingen->editOmgeving($formData); >> } else { >> $toestellen->setFormData($formData); >> $toestellen->editItem(); >> } >> //update gelukt - gebruiker laten weten >> $this->flash->addMessage("De gegevens werden gewijzigd!"); >> >> $this->_helper->redirector->gotoUrl('/speelpleinen/toestel/id/'.$this->id >> . >> '/speelplein/'.$this->speelpleinId); >> } else { >> $form->populate($formData); >> } >> } else { // het gaat om het bestandenform upload ding >> if($bestandenForm->isValid($formData)) { >> if ($_FILES['file1']['tmp_name']) { >> $formData['file1'] = $_FILES['file1']; >> } >> //doe iets er mee >> $bestanden = new Bestanden(); >> $uploaden = $bestanden->saveBestand($formData); >> //update gelukt - gebruiker laten weten >> if($uploaden) { >> $this->flash->addMessage("Het bestand werd toegevoegd."); >> } else { >> $this->flash->addMessage("Er was een fout. Probeer opnieuw."); >> } >> $this->_helper->redirector->gotoUrl('/toestellen/edit/id/'.$this->id . >> '/speelplein/'.$this->speelpleinId); >> } else { >> $bestandenForm->populate($formData); >> print_r($bestandenForm->getMessages()); >> $id = $this->id; >> if($id > 0) { >> $toestel = $toestellen->fetchRow('id=' . $id); >> $form->populate($toestel->toArray()); >> } >> } >> } >> } else { >> $id = $this->id; >> if($id > 0) { >> $toestel = $toestellen->fetchRow('id=' . $id); >> $form->populate($toestel->toArray()); >> } >> } >> } >> >> >> This is the code of the form (BestandenForm.php): >> >> class BestandenForm extends Zend_Form >> { >> protected $_front; >> >> public function setFrontController() >> { >> $this->_front = Zend_Controller_Front::getInstance(); >> } >> >> public function init() >> { >> $this->setFrontController(); >> $baseUrl = $this->_front->getRequest()->getBaseUrl(); >> >> //formulier aanmaken en basiszaken instellen >> $this->setName('bestanden') >> ->setAttrib('id','bestanden') >> ->setAttrib('class','bestanden') >> ->setAttrib('enctype','multipart/form-data'); //er is mogelijke >> file-upload! >> >> //verborgen id veld >> $id = new Zend_Form_Element_Hidden('id'); >> $id->setValue($this->_front->getRequest()->getParam('id')); >> $this->addElement($id); >> >> //verborgen veldveld >> $sectie = new Zend_Form_Element_Hidden('sectie'); >> $sectie->setValue($this->_front->getRequest()->getControllerName()); >> $this->addElement($sectie); >> >> >> >> $this->setElementDecorators(array( >> 'ViewHelper', >> 'Errors', >> array('Description',array('escape'=>false, 'tag'=>'span')), >> array(array('data' => 'HtmlTag'), array('tag' => 'td', 'class' => >> 'element')), >> array('Label', array('tag' => 'td','placement' => 'prepend')), >> array(array('row' => 'HtmlTag'), array('tag' => 'tr')) >> )); >> >> >> //file upload >> //mag leeg zijn >> $size = '6MB'; >> //file upload moet naar uploadPath uit config.ini >> $reg = Zend_Registry::get('config'); >> >> //file upload >> $file1 = new Zend_Form_Element_File('file1'); >> $file1->setRequired(true) >> ->addValidator('NotEmpty',true) >> ->addValidator('Count',false,array('min' => 1, 'max' => 1)) //slechts >> 1 bestand toegelaten >> ->addValidator('MimeType', true, array('application/pdf')) >> ->addValidator('Extension',false,array('pdf')) >> ->addValidator('Size',false,array('max' => $size)) //max filesize >> //->setDestination($reg->uploadPath) >> ->setMaxFileSize(6291456); >> >> //foutmelding aanpassen naar eigen verwoording >> $file1->getValidator('NotEmpty')->setMessage('Je moet een bestand >> selecteren via de Bladeren knop.'); >> $file1->getValidator('Size')->setMessage('De bestandsgrootte van een >> bestand mag niet groter zijn dan ' . $size . '.'); >> $file1->getValidator('Extension')->setMessage('Je kan enkel >> PDF-bestanden toevoegen.'); >> $file1->getValidator('MimeType')->setMessage('Je kan enkel >> PDF-bestanden toevoegen.'); >> >> $this->addElement($file1,'file1'); >> //$file1->removeDecorator('ViewHelper'); >> $file1->addDecorator('File'); >> >> //submitbutton >> $submit = new Zend_Form_Element_Submit('Upload'); >> $submit->setDecorators(array( >> 'ViewHelper', >> array('Description',array('escape'=>false,'tag'=>'span')), >> array(array('data' => 'HtmlTag'), array('tag' => 'td', 'class' => >> 'element')), >> array(array('label' => 'HtmlTag'), array('tag' => 'td', 'placement' => >> 'prepend')), >> array(array('row' => 'HtmlTag'), array('tag' => 'tr')), >> )); >> $id->setDecorators(array( >> 'ViewHelper', >> array(array('data' => 'HtmlTag'), array('tag' => 'td', 'class' => >> 'hidden')), >> array(array('label' => 'HtmlTag'), array('tag' => 'td', 'placement' => >> 'prepend')), >> array(array('row' => 'HtmlTag'), array('tag' => 'tr')), >> )); >> $sectie->setDecorators(array( >> 'ViewHelper', >> array(array('data' => 'HtmlTag'), array('tag' => 'td', 'class' => >> 'hidden')), >> array(array('label' => 'HtmlTag'), array('tag' => 'td', 'placement' => >> 'prepend')), >> array(array('row' => 'HtmlTag'), array('tag' => 'tr')), >> )); >> //button aan form toevoegen >> $this->addElement($submit); >> >> $this->setDecorators(array( >> 'FormElements', >> array('HtmlTag', array('tag' => 'table')), >> 'Form', >> )); >> } >> >> } >> >> >> >> thomasW wrote: >>> >>> As you setRequired to true, you should get a failure in any of the above >>> cases when the validation fails. >>> So I expect that you have a general problem displaying error messages. >>> >> >> -- >> View this message in context: >> http://www.nabble.com/User-uploads-file-bigger-than-what%27s-allowed-in-php.ini%2C-can-it-be-caught--tp21936346p22068701.html >> Sent from the Zend Framework mailing list archive at Nabble.com. > > > -- View this message in context: http://www.nabble.com/User-uploads-file-bigger-than-what%27s-allowed-in-php.ini%2C-can-it-be-caught--tp21936346p22089382.html Sent from the Zend Framework mailing list archive at Nabble.com.
