sfFileValidator pre-defined categories
March 14, 2007
I recently took a look at the source of the sfFileValidation class and found out about a nice, undocumented, “feature” – pre-defined categories. Currently there is just one for web-images, but i hope the list will grow soon.
<?php $categories = array( '@web_images' => array( 'image/jpeg', 'image/pjpeg', 'image/png', 'image/x-png', 'image/gif', ), ); ?>
So, you could either write:
fields:
image:
required:
msg: Please upload an image file
file: True
sfFileValidator:
mime_types:
- 'image/jpeg'
- 'image/pjpeg'
- 'image/png'
- 'image/x-png'
- 'image/gif'
mime_types_error: Only PNG, JPEG and GIF files are allowed
or simply go with:
fields:
image:
required:
msg: Please upload an image file
file: True
sfFileValidator:
mime_types: @web_images
mime_types_error: Only PNG, JPEG and GIF files are allowed
Very useful for lazy developers ;)
March 14, 2007 at 1:50 pm
[...] 14th, 2007 After i found out about the pre-defined categories in sfFileValidator i got curious and took a look at the other validator classes. Turns out there is even more [...]