Issues

ZF-5126: Multi files upload handling

Description

I just wanna ask about multi files upload validation/filter handling by Zend_File_Transfer_Adapter Is it possible to add same validators or filters for different files in same upload session ?

I try following code but not working ( assumes I have a form post data with 2 input file named 'file1" and "file2" )


public function indexAction()
{
     $request = $this->getRequest();
     if ($request->isPost()) {
        $upload = new Zend_File_Transfer_Adapter_Http();
        $upload->addValidator('Extension', true, array('pdf'), 'file2');
        $upload->addValidator('Extension', true, array('doc'), 'file1');
        var_dump($upload->isValid());
        exit;
      }
}
  • expected result : will return true if I upload .pdf type file for 'file1' and .doc type file for 'file2'
  • result : it will never accept '.pdf' type file (its only accept .doc type file) (please correct me if my code is for wrong purpose)

doing some little research, I found even we separate the validator for each files, the validator name is refering to same adapter validator stacks, so if we are using same validator for different file ( in our case 'Extension' ) if will refer to last 'Extension' validator in the stack and ignoring previous added 'Extension' validator, in other word we must add and remove 'same validator' to validating multi files upload with different validating policy.

is it possible to add 'custom validator name' features to validators/filters so when we need 2 or more same validator/filter with different policy (in our case 2 'Extension' validator, one for pdf files, and one for doc file) we can avoid validator/filter name conflict.

btw If there already feature like this, would you please tell me how to use it? or maybe it should be like this by design

Regards, Bandirsen

and sorry for my english :)

Comments

Manual clearly states that multiple validators of the same type are not allowed and will overwrite each other.

Hi Thomas,

Thanks for reply so it's by design.
then in my use case, we must repeating add 'Extension Validator' and call isValid() method manually for each file when validating upload multiple files with with different extension type.

Is there any plan to change behavior this in future ?

Hi Thomas,

Sorry if I late for this. I see this issue is still open, and I think we should change this issue status to closed / resolved. I was trying to change its status but I can find how to do it.

Regards, Bandirsen

Hello Thomas,

Any news about this improvement?

By the way, I hope messages will be refactored to include the name of the input as key of the messages (like for standard validators). For example, we could have something like this:


array(2) {
  ["MEDIA"] => array(1) {
    ["fileSizeTooBig"] => string(76) "Maximum allowed size for file 'yahoo.jpg' is '20kB' but '154.77kB' detected"
  }
  ["THUMBNAIL"] => array(1) {
    ["fileSizeTooBig"] => string(77) "Maximum allowed size for file 'google.jpg' is '5kB' but '181.47kB' detected"
  }
}

Standard validators to not add the element name to the message. It depends on the validator how the message will look like.

Some prework within Zend_Validate has already been done. But it still needs some time. Several other issues have more votes than this one. And I am vote-driven ;-)

So as summary: Not forgotten... please be patient. :-)

Bulk change of all issues last updated before 1st January 2010 as "Won't Fix".

Feel free to re-open and provide a patch if you want to fix this issue.