[SOLVED] Multiple Upload Validate

Hi,

Can anyone show a working example of how to validate multiple files? In my code, validation works if a single file is uploaded; but not when more than 1 is uploaded.

For example: I only allow jpg, gif, and png. I try to upload an .ini file and the validation works. If I try to upload a jpg and an .ini file, the validation doesn’t trigger an error.

Model:




public $images;


// Rules

array('images', 'file', 'types'=>'jpg, gif, png', 'allowEmpty' => true,),



Controller:




$model->images = CUploadedFile::getInstances($model, "[$i]images");



View:




<?php echo CHtml::activeFileField($model, 'images', array('multiple' => true)); ?>



In the view, I have tried setting the name to include the double square brackets but this doesn’t work either.

Ex: <?php echo CHtml::activeFileField($model, ‘images’, array(‘name’ => ‘images[]’, ‘multiple’ => true)); ?>

Any ideas?

I have two models (and tables): Portfolio & PortfolioImage. A Portfolio can have many PortfolioImages, hence the relationship,


'images' => array(self::HAS_MANY, 'PortfolioImage', 'portfolio_id'),

.

I need to have the file input on the Portfolio Form - see screenshot.

I would also like to validate the files through the Portfolio. Is this possible and can you point me to some examples to show how to accomplish this?

Thanks.

Had to set the maxFiles property of the file validator to greater than 1! Arrrrrgggggg.


array('imageList', 'file', 'types'=>'jpg, gif, png', 'allowEmpty' => true, 'maxFiles' => 10),

Thanks, i have got the same issue.