Last active
          August 29, 2015 13:55 
        
      - 
      
- 
        Save tristanlins/8784568 to your computer and use it in GitHub Desktop. 
    FilesType for Symfony 2, allows HTML5 multiple file upload.
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | <?php | |
| namespace Acme\DemoBundle\Form\Type; | |
| use Symfony\Component\HttpFoundation\File\UploadedFile; | |
| /** | |
| * Class FilesmData | |
| */ | |
| class FilesmData | |
| { | |
| /** | |
| * @var UploadedFile[] | |
| */ | |
| protected $files = array(); | |
| /** | |
| * @param UploadedFile[] $files | |
| */ | |
| public function setFiles(array $files) | |
| { | |
| $this->files = $files; | |
| return $this; | |
| } | |
| /** | |
| * @return UploadedFile[] | |
| */ | |
| public function getFiles() | |
| { | |
| return $this->files; | |
| } | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | <?php | |
| namespace Acme\DemoBundle\Form\Type; | |
| use Symfony\Component\Form\Extension\Core\Type\FileType; | |
| use Symfony\Component\Form\FormInterface; | |
| use Symfony\Component\Form\FormView; | |
| use Symfony\Component\OptionsResolver\OptionsResolverInterface; | |
| use Symfony\Component\Validator\Constraints as Assert; | |
| /** | |
| * Class FilesType | |
| */ | |
| class FilesType extends FileType | |
| { | |
| public function buildView(FormView $view, \Symfony\Component\Form\FormInterface $form, array $options) | |
| { | |
| parent::buildView($view, $form, $options); | |
| $view->vars['full_name'] .= '[]'; | |
| $view->vars['attr']['multiple'] = 'multiple'; | |
| } | |
| /** | |
| * {@inheritdoc} | |
| */ | |
| public function setDefaultOptions(OptionsResolverInterface $resolver) | |
| { | |
| parent::setDefaultOptions($resolver); | |
| $resolver->setDefaults( | |
| array( | |
| 'data_class' => null, | |
| ) | |
| ); | |
| } | |
| public function getName() | |
| { | |
| return 'files'; | |
| } | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment