yii-dream-team/yii2-upload-behavior

File Instances are not recognized when using array of file_input.

Opened this issue · 0 comments

I have a page with several models, arranged as array, and they have a file_input control.
But the attribute never gets the UploadedFile object because of differences in the name of the files in the $_FILES array.
I got around this problem by using a third check in BeforeValidade event. Maybe you guys want to use this solution in yii2-upload-behavior.

    if (empty($this->file)) {
        $this->file = UploadedFile::getInstanceByName($this->attribute);
        if (empty($this->file))
        {
            $id=$this->owner->id;
            $att=$this->attribute;
            $name= $this->owner->formName()."[$id][$att]";
            $this->file = UploadedFile::getInstanceByName($name); 
        }

   }

    if ($this->file instanceof UploadedFile) {
        $this->owner->{$this->attribute} = $this->file;
    }
}