34
validatefilename
validate_filename
SYNOPSIS
validate_filename($name)
DESCRIPTION
validate_filename
returns true
if $name
is a valid file name, false
otherwise.
CODE
- function validate_filename($name) {
- return preg_match('/^[[:alnum:]]+[[:alnum:] \._-]*(\.[[:alnum:]]+)?$/', $name);
- }
validate_filename
returns true
if $name
starts with an alphanumeric character followed by a series of alphanumeric characters, spaces, dots, underscores or dashes terminated by a dot and at least one alphanumeric character.
IMPORTANT: Adapt this function to the syntax of the file names accepted by the website.
EXAMPLE: With the regular expression '/^[0-9\pL][0-9\pL \._+-]*(\.[[:alnum:]]+)$/u'
, accented characters are accepted and a file name must start with a letter or a digit and end with an extension with in between in option, letters, digits, spaces, dots, underscores, plus signs and dashes.
Comments