ZF-8064: File validation by "IsImage" broke upload process

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

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.

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

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

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.