New IS_UPLOAD_FILENAME validator checks if name and extension of file uploaded through file input matches given criteria.
Note that this does not ensure the file type in any way. String is partitioned into name and extension parts by splitting it with dot character.
INPUT(_type='file', _name='name', requires=IS_UPLOAD_FILENAME(filename=None,
extension=None,
lastdot=True,
case=1))
If there is no dot present, extension checks will be done against empty string and filename checks against whole value.
Examples:
Check if file has a pdf extension (case insensitive):
INPUT(_type='file', _name='name', requires=IS_FILENAME(extension='pdf'))
Check if file has a tar.gz extension and name starting with backup:
INPUT(_type='file', _name='name', requires=IS_FILENAME(filename='backup.*',
extension='tar\.gz',
lastdot=False))
Check if file has no extension and name matching README (case sensitive):
INPUT(_type='file', _name='name', requires=IS_FILENAME(filename='^README$',
extension='^$',
case=0))