Upload works, but MultipleUpload does not work!

hi,

I trying the Multiple upload things, I did the example in 106 single file upload, it works totally fine, then I try to multiple update files like code on page 109, it does not work. looks like there is validate problem, I always get $model->validate() false, with errors like this:




array(1) {

  ["file"]=>

  array(1) {

    [0]=>

    string(21) "File cannot be blank."

  }

}



I am sure, I have choose 3 times file from disk, and click the upload button. I google some, but not find good solution, and btw. code on page 109:




$files = CUploadedFile::getInstance($model, 'file');



man should here use getInstance or getInstances? I am totally confused, Please help. Thank you very much.

Hi, it does not work for me too. i tried with the getInstances method, it returns an array of files, but it does not work also. The error is file cannot be blank.

you can use this: http://www.yiiframework.com/wiki/326/nice-file-upload-tool-on-yii-framework/

is very efficient, and easy to implement.

IN Upload.php

array(‘file’, ‘file’, ‘types’=>‘zip’,‘allowEmpty’ => true),

IN UploadController.php

$files=CUploadedFile::getInstances($model,‘file’);

IN view.php

<?php echo CHtml::activeFileField($model, "file[0]")?>

<?php echo CHtml::activeFileField($model, "file[1]")?>

This uploads the files but does no validation upon either of the files selected. Not a good solution. The author should comment how to fix this obviously this code hasn’t been tested before written in the book.

I got same problem.

Do anyone have a solution for this ?

hello my first response to the forum, always read he never contributes, c’mon

I to using a multiupload with multiple files

so do not know if it actually looked rather more follows the MVC pattern code


#Model


public function rules()

	{


		return array(

		...

	array('picture', 'pictureRule'),

	

	

	.. );

	}

	

	

	public function pictureRule()


			 {

				 $picture_test=CUploadedFile::getInstancesByName('picture');


				 if(empty($picture_test)) 

				 {

					  $this->addError('pictureRule', 'Error not file blank!');

				 	  return false;

				 }else{

					 return true;


				 }


		     }

		

#Controler




*remember to put that part of the instance file after validation


* i use  [url="http://www.yiiframework.com/extension/euploadedimage/"]EUploadImage[/url] extension for good make thumbs

public function actionCreate()

{




$model=new Produts;




if(isset($_POST['Produts']))

{

	

$model->attributes=$_POST['Produts'];

if($model->validate()){   


$picture = EUploadedImage::getInstancesByName('picture');

Thanks

Try this -


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