UploadedFile and mulitple files

I have a form with a few file inputs, the’re going like this:

File[1]

File[2]

File[3]

I know I can handle 'em with getInstancesByName, but I need to pass empty inputs and keep the sequence.

So, if the second file wasn’t loaded I need to do something like this:




$str1 = Html::img(file1.jpg);

$str2 = "No file";

$str3 = Html::img(file3.jpg);



I can’t do it with just foreach’ing the UploadedFile array.

Can anyone give me advice on how to do this without simple operations with $_FILES array directly?

So, the only way I’ve found to keep track of images that weren’t uploaded is this re-mapping:




 public function mapResultPics($upload = [])

    {

        $count = count($upload['name']);

        if ($count === 0)

            return false;


        for ($i = 1; $i <= $count; $i++) {

            $result[] = new \yii\web\UploadedFile([

                'name'     => $upload['name']       [$i],

                'tempName' => $upload['tmp_name']   [$i],

                'type'     => $upload['type']       [$i],

                'size'     => $upload['size']       [$i],

                'error'    => $upload['error']      [$i],

            ]);

        }


        return $result;

    }