问题描述
我试图通过表单上传多个文件,但是我一次只能上传一个文件,而最后一个文件是在浏览器中标记的。有没有办法使用一个简单的形式上传Symfony2更多的图像?
这里是我用来标记多个文件的形式的树枝模板:
{{form_widget(form.post_image,{'attr':{'multiple':'multiple'}})}}
我真的不知道什么是错的。检查你的模板(也许错误的enctype ...或名称attr missmatching)
首先尝试做一个单一文件上传,检查文档:
一旦它工作,您必须编辑一些行。
- 添加输入文件的多个属性。
- append []在输入文件名属性的末尾(我的是
创建... []因为我的表单类名称是创建,如果你是
的createType它将是createType ... [])
- init $文件作为一个数组。
复制/粘贴您的代码。
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' }}) }}
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.
- add input file multiple attribute.
- append [] at the end of the input file name attribute (mine iscreate...[] because my form class name is create, if your iscreateType it will be createType...[])
- init $files as an array.
Copy/paste your code here.
这篇关于用Symfony2多文件上传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!