Symfony – multiple file upload symfony 2

symfony

How to use multiple files upload in symfony? I'm not really
sure how to do it 'the symfony way'. I read How to handle File Uploads with Doctrine, but how upload many files?

I try use collection field type and add setFiles method to object model

public function setFiles($files)
{
    $this->files = $files;
    foreach ($files as $file) {
        $file->setObject($this);
    }
}

but have exception (this always worked for normal model without any files)

Fatal error: Call to undefined method
Symfony\Component\HttpFoundation\File\UploadedFile::setObject()

please help me.

UPDATED:
I use for main object second form with file, and…

      $files = $this->getRequest()->files->get('val_image');
      foreach($files as $file){
            $foto = new Foto;
            $foto->setFile($file);
            $foto->setPremises($premises->getPremises());
            $this->getEm()->persist($foto);
        }

it's works 🙂

Related Topic