Multiple File Uploads


I have a problem uploading several images:

In my view I have several textArea which are linked with a CHtml::activeFilefield (I also have tried with CHtml::FileField)


foreach($myModel as $paso){

echo CHtml::label('Descripción','');

echo CHtml::textArea('MyModel[description][]',


		array('rows'=>2, 'cols'=>50, 'class'=>'span8','id'=>$paso->id)));

//echo CHtml::FileField('MyModel[imagen_file][]', '', array('size' => 50,'id'=>'MyModel_imagen_file'));

echo CHtml::activeFilefield ($paso, 'imagen_file', array('size' => 50,'id'=>'MyModel_imagen_file'.$cont));


In my controller:


$images = CUploadedFile::getInstancesByName('MyModel');

All the images arrive to my controller, the problem I have, is how to know which image is linked with which textarea.

For example I have the next values:

TextArea1: Lorem ipsum 1…

Image1: Empty

TextArea2: Lorem ipsum 2…

Image2: Empty

TextArea3: Lorem ipsum 3…

Image3: MyFile.png

Debugging, in my $images array, I only have one image:

$images	Array [1]	

	0	CUploadedFile	

		_name	MyFile.png	

		_tempName	D:\\wamp\\tmp\\phpC360.tmp	

		_type	image/png	

		_size	11553	

		_error	0

So how can I know that "MyFile.png" is linked with TextArea3? Is it possible to add any params to CHtml::activeFilefield so I can identify which "activeFilefield" has an image?

Thanks in advance.

the easiest i can think of right now is do a simple if condition, for instance

if(isset($_FILES['image1']) && !empty($_FILES['images1']) 


  //image for first textarea


elseif(isset($_FILES['image3']) && !empty($_FILES['images3']) 


  //image for second textarea


elseif(isset($_FILES['image3']) && !empty($_FILES['images3'])


  //image for third textarea


Thanks alirz23. The problem is when in my Controller I get

$images = CUploadedFile::getInstancesByName('MyModel');

There´s no way to find any info about image1, image2 or image3.

Finally, I got it working like this, adding in my view a hiddenField:

echo CHtml::FileField('MyModel[imagen_file][]', '',array('size' => 50));

echo CHtml::hiddenField('MyModel[imagen_file][]',$cont);

This way, with the $cont var, I know when I submit an image, to which textArea is linked.