Zend Framework

File validation by "IsImage" broke upload process

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Major Major
  • Resolution: Cannot Reproduce
  • Affects Version/s: 1.9.3
  • Fix Version/s: 1.10.0
  • Component/s: Zend_Validate_File
  • Labels:
    None

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!

Activity

Hide
Thomas Weidner added a comment -

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.

Show
Thomas Weidner added a comment - 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.
Hide
Thomas Weidner added a comment -

I just tried to reproduce, but I am not able... all works like expected.
Can you give additional informations ?

Show
Thomas Weidner added a comment - I just tried to reproduce, but I am not able... all works like expected. Can you give additional informations ?
Hide
Vasa Grujic added a comment -

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:
------------------------------------------------------------------------------------------------------------------------------------------
<?php

class PortraitForm extends Zend_Form
{
public function init()

{ $buttonDecorator = array('ViewHelper', array('ViewScript', array('viewScript' => '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

Show
Vasa Grujic added a comment - 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: ------------------------------------------------------------------------------------------------------------------------------------------ <?php class PortraitForm extends Zend_Form { public function init() { $buttonDecorator = array('ViewHelper', array('ViewScript', array('viewScript' => '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
Hide
Thomas Weidner added a comment -

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.

Show
Thomas Weidner added a comment - 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.

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: