zend-frameworkzend-validatezend-file

Skipping Validation for a single file in Zend_File_Transfer


For creating a business I upload 5 images along with a .csv file. I have used following zend validators

$upload = new Zend_File_Transfer();
        $upload->addValidator('Count', false, array('min' =>1, 'max' => 6))
               ->addValidator('Size', false, array('max' => '1Mb'))
               ->addValidator('ImageSize', false, array('minwidth' => 50,
                                                        'maxwidth' => 1000,
                                                        'minheight' => 50,
                                                        'maxheight' => 1000));

When I upload the CSV I get an error saying ImageSize not detected. Is there any way that I can skip ImageSize validator for .csv file?


Solution

  • And I figured out how to do it!!

    $upload = new Zend_File_Transfer();
        $files = $upload->getFileInfo();
        foreach ($files as $fields => $contents)
        {
            if ($fields!= 'filename6')  -- Skipping the validation for csv file
            {
                $upload->addValidator('Count', false, array('min' =>1, 'max' => 6),$fields)
                       ->addValidator('Size', false, array('max' => '1Mb'),$fields)
                       ->addValidator('ImageSize', false, array('minwidth' => 50,
                                                                'maxwidth' => 1000,
                                                                'minheight' => 50,
                                                                'maxheight' => 1000),$fields);
            }
            elseif ($fields == 'filename6') -- To validate only csv file
            {
                $upload->addValidator('Extension', false, 'csv', $fields)
                       ->addValidator('Size', false, array('max' => '1Mb'),$fields);
            }
        }