Fileinput Multiple

<?= $form->field($model, 'files')->fileInput(['multiple' => 'multiple']) ?>


<input type="file" id="uploadform-files" name="UploadForm[files]" multiple="multiple">

However, the name should have a ‘[]’ suffix, like:

<input type="file" id="uploadform-files" name="UploadForm[files][]" multiple="multiple">

How can I accomplish this?


<?= $form->field($model, 'files')->fileInput(['multiple' => 'multiple', 'name' => 'UploadForm[files][]']) ?>

This works. Also passes $model->validate();. Feels hackerish, is it?

Can you show the Controller logic for the file upload. For me if the file upload is none then the validate fails.



	public function actionUpload($id) {

	    $album = $this->findModel($id);

	    $model = new UploadForm;


	    if ($model->load(Yii::$app->request->post()) && $model->validate()) {	    

	        $files = UploadedFile::getInstances($model, 'files');


            // TODO type filter

            foreach($files as $file) {

                if($file->type == 'image/jpeg') {

                    $this->savePhoto($album, $file);




			return $this->redirect(['view', 'id' => $album->id]);

		} else {

        	return $this->render('upload', [

        	    'album' => $album,

        	    'model' => $model





I noticed that the UploadForm model has no rules, so that might be why mine validates and yours doesn’t :P

Can’t test the rules right now.