多文件上传 symfony 2 [英] multiple file upload symfony 2
问题描述
如何在symfony中使用多个文件上传?我不是真的确定如何做到symfony 方式".我读了 How to handle File Uploads with Doctrine,但是如何上传多少文件?
我尝试使用 collection field type 并添加 setFiles 方法到对象模型
<块引用>公共函数 setFiles($files){$this->files = $files;foreach ($files as $file) {$file->setObject($this);}}
但有例外(这总是适用于没有任何文件的普通模型)
<块引用>致命错误:调用未定义的方法Symfony\Component\HttpFoundation\File\UploadedFile::setObject()
请帮帮我.
更新:我用文件作为主要对象的第二种形式,并且...
<块引用> $files = $this->getRequest()->files->get('val_image');foreach($files as $file){$foto = 新照片;$foto->setFile($file);$foto->setPremises($premises->getPremises());$this->getEm()->persist($foto);}
它的作品:)
也许这个插件可以帮到你:
https://github.com/caoimhin/Symfony-jQuery-File-Upload/blob/master/Resources/public/README.md
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 :)
Maybe this plugin can help you:
https://github.com/caoimhin/Symfony-jQuery-File-Upload/blob/master/Resources/public/README.md
这篇关于多文件上传 symfony 2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!