1

I am quite newbie in zend framework 2. I am not working with file uploading in a standard manner before in zend framework 2. I am in stuck to validate image file for size, extension etc in inputfilter. Here is my validation code which is not working at all.

$inputFilter->add(
    array(
        'name' => 'WEB_LOGO',
        'required' => false,
        'validators' => array(
            array(
                'name' => 'Zend\Validator\File\Size',
                'options' => array(
                    'min' => 120,
                    'max' => 200000,
                    ),
                'name' => 'Zend\Validator\File\Extension',
                'options' => array(
                    'extension' => 'png',
                    ),
                ),
            ),
        )
    );

The zend framework 2 file uploading process seems to me more complicated. Is it wise to upload file using raw php function?

However, how can i validate image file easily in inputfilter and it will be great help for me if anyone guide me how to upload two or three file input easily in zend framework 2.

Thanks for kind attention.

2
  • Your provided suggestion exclusively used for zend 1 Commented Jun 9, 2014 at 6:11
  • The value of the validators key seems invalid. It should be stacked as array(arr1(name, options), arr2(name, options)) etc.. Commented Jun 9, 2014 at 10:16

1 Answer 1

2

The code you have tried will only utilize the Extension and not the Size validator.

As @foozy said, try this to get both working -

$inputFilter->add(
    array(
        'name' => 'WEB_LOGO',
        'required' => false,
        'validators' => array(
            array(
                'name' => 'Zend\Validator\File\Size',
                'options' => array(
                    'min' => 120,
                    'max' => 200000,
                ),
            ),
            array(
                'name' => 'Zend\Validator\File\Extension',
                'options' => array(
                    'extension' => 'png',
                ),
            ),
        ),
    )
);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.