Reputation: 41
I have a buildForm
method:
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('photo', 'file', array('label' => false, 'required' => false));
}
How to make choose file window show only .png and .jpeg files?
Upvotes: 1
Views: 1720
Reputation: 347
I think this should work:
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('photo',
'file',
array('label' => false,
'required' => false,
'attr' => array('accept' => 'image/jpeg,image/png')
)
);
}
The HTML for that is
<input type="file" accept="image/jpg,image/png">
However that's not supported by any browser.
Upvotes: 3
Reputation: 57719
Use accept
like:
<input type="file" accept=".png,.jpg,.jpeg" />
Or in your case:
$builder->add('photo', 'file', array('label' => false, 'required' => false,
'accept' => ".png,.jpg,.jpeg" ));
Upvotes: 5