ZF-8064: File validation by "IsImage" broke upload process
Issue Type: Bug Created: 2009-10-13T06:20:27.000+0000 Last Updated: 2009-10-18T13:08:17.000+0000 Status: Resolved Fix version(s): - 1.10.0 (27/Jan/10)
Reporter: Vasa Grujic (vasa) Assignee: Thomas Weidner (thomas) Tags: - Zend_Validate_File
Related issues:
Attachments:
Description
File validation by "IsImage" broke upload process. No php warning or error, no validation errors even if file type is incorrect.
Example 1: $this->addElement('file', 'file', array( 'size' => '40', 'label' => 'Seleccione un archivo de imagen que desea subir.', 'required' => true, 'description' => 'Tipo de archivos permitidos: bmp, gif, jpg, png', 'validators' => array( 'Size' => array('min' => 20000, 'max' => 1000000), 'IsImage' => array('image/bmp', 'image/gif', 'image/jpeg', 'image/pjpeg', 'image/png') ) ));
Example 2: $this->addElement('file', 'file', array( 'size' => '40', 'label' => 'Seleccione un archivo de imagen que desea subir.', 'required' => true, 'description' => 'Tipo de archivos permitidos: bmp, gif, jpg, png', 'validators' => array( 'Size' => array('min' => 20000, 'max' => 1000000), 'IsImage' ) ));
With ZF 1.9.2 everything is OK!
Comments
Posted by Thomas Weidner (thomas) on 2009-10-15T14:25:40.000+0000
When the process is broken then there must be a returned value, error message, validation message or exception. Something must be returned.
Or you have changed anything... only updated parts of the framework instead of the complete framework?
Try to call the validator standalone so you can give us something reproducable.
You could also try trunk and see if this issue exists also for the next major release.
Posted by Thomas Weidner (thomas) on 2009-10-16T00:44:29.000+0000
I just tried to reproduce, but I am not able... all works like expected. Can you give additional informations ?
Posted by Vasa Grujic (vasa) on 2009-10-16T02:51:51.000+0000
Scenario: When hint the submit button, after choosing the image file to upload, page is just refreshed. Without any feedback. In case without IsImage validation everything go smooth.
Form:
'decorators/form/button.phtml', 'placement' => false))); $hiddenDecorator = array('ViewHelper', array('ViewScript', array('viewScript' => 'decorators/form/hidden.phtml', 'placement' => false)));
$this->setMethod('post');
$this->setName('upload');
$this->setAttrib('enctype', 'multipart/form-data');
$this->addElement('file', 'file', array(
'size' => '40',
'label' => 'Seleccione un archivo de imagen que desea subir.',
'required' => true,
'description' => 'Tipo de archivos permitidos: bmp, gif, jpg, png',
'validators' => array(
'Size' => array('min' => 10000, 'max' => 1000000),
'Count' => array('min' => 1, 'max' => 1),
'IsImage' => array('image/bmp', 'image/gif', 'image/jpeg', 'image/pjpeg', 'image/png'),
'NotEmpty'
)
));
$this->addElement('submit', 'submit', array(
'decorators' => $buttonDecorator,
'ignore' => true,
'label' => 'Subir imagen',
));
$this->addElement('hash', 'csrf', array(
'decorators' => $hiddenDecorator,
'ignore' => true,
));
$this->setDecorators(array(
'FormElements',
array('HtmlTag', array('tag' => 'dl', 'class' => 'basic-form file')),
array('Description', array('placement' => 'prepend')),
'Form'
));
}
}
-
Controller:
-----------
if ($this->\_request->isPost()) {
$formData = $this->_request->getPost();
if ($form->isValid($formData)) {
$upload = new Zend_File_Transfer_Adapter_Http();
$uploadDestination = APPLICATION_PATH . '/../public/tmp/portraits/';
$upload->setDestination($uploadDestination);
if($upload->receive()):
// Do something
endif;
}
}
-
ZF 1.9.3 FULL, Autoload. Development environment: Mac OS X 10.6.1 with MAMP 1.7.2
Posted by Thomas Weidner (thomas) on 2009-10-18T13:07:39.000+0000
I see no failure...
The default decorators are erased and, as described in FAQ and manual, in this case the file element is not rendered correctly. The seen behaviour can be a result.
Additionally you are using 2 different adapters... this can also lead to unexpected behaviour.
As third, when you see no failure, returned message or exception then you must have configured something wrong... Zend\_File can not suppress failures or exceptions. And by erasing the decorators a notice is triggered which you don't see. Check your configuration / settings.