用Symfony2多文件上传 [英] Multiple file upload with Symfony2

查看:111
本文介绍了用Symfony2多文件上传的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过表单上传多个文件,但是我一次只能上传一个文件,而最后一个文件是在浏览器中标记的。有没有办法使用一个简单的形式上传Symfony2更多的图像?
这里是我用来标记多个文件的形式的树枝模板:

  {{form_widget(form.post_image,{'attr':{'multiple':'multiple'}})}} 



我真的不知道什么是错的。检查你的模板(也许错误的enctype ...或名称attr missmatching)

首先尝试做一个单一文件上传,检查文档:


  1. 档案字段类型

  2. 如何处理文件上传与教义

一旦它工作,您必须编辑一些行。


  1. 添加输入文件的多个属性。
  2. append []在输入文件名属性的末尾(我的是
    创建... []因为我的表单类名称是创建,如果你是
    的createType它将是createType ... [])
  3. 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:

  1. file Field Type
  2. How to handle File Uploads with Doctrine

Once it works, you have to edit some lines.

  1. add input file multiple attribute.
  2. append [] at the end of the input file name attribute (mine is create...[] because my form class name is create, if your is createType it will be createType...[])
  3. init $files as an array.

Copy/paste your code here.

这篇关于用Symfony2多文件上传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆