使用 Symfony2 上传多个文件 [英] Multiple file upload with Symfony2
问题描述
我正在尝试通过表单上传多个文件,但我一次只能上传一个文件,最后一个是我在浏览器中标记的.有没有办法使用简单的表单使用 Symfony2 上传更多图像?这是我用来标记多个文件的表单的树枝模板:
I'm trying to upload multiple files via a form, but I can only upload one file at a time, the last one I mark in the browser. Is there a way to upload more images with Symfony2 using a simple form? Here is the twig template of the form I'm using to be able to mark more than one file:
{{ form_widget(form.post_image, { 'attr': {'multiple': 'multiple' }}) }}
推荐答案
不需要额外的类(gallery_manger 服务除外,但您描述的问题之前发生过...)
No extra classes needed (except the gallery_manger service but the issue you describe happens before...)
我真的不知道出了什么问题.检查您的模板(可能是错误的编码类型...或名称属性不匹配)
I don't really know what's wrong. Check for your template (maybe wrong enctype... or name attr missmatching)
先尝试做单文件上传,查看文档:
first try to do a single file upload, check the documentation:
一旦成功,你必须编辑一些行.
Once it works, you have to edit some lines.
- 添加输入文件多个属性.
- 在输入文件名属性的末尾追加[](我的是create...[] 因为我的表单类名是 create,如果你是createType 它将是 createType...[])
- 将 $files 初始化为一个数组.
在此处复制/粘贴您的代码.
Copy/paste your code here.
这篇关于使用 Symfony2 上传多个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!