Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File Instances are not recognized when using array of file_input. #13

Open
phdcoder opened this issue Dec 19, 2015 · 0 comments
Open

File Instances are not recognized when using array of file_input. #13

phdcoder opened this issue Dec 19, 2015 · 0 comments

Comments

@phdcoder
Copy link

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;
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant