Skip to content

Instantly share code, notes, and snippets.

@dlueth
Created June 27, 2013 21:27
Show Gist options
  • Save dlueth/5880552 to your computer and use it in GitHub Desktop.
Save dlueth/5880552 to your computer and use it in GitHub Desktop.
PHP validator that checks if a given string is a valid/allowed filename across operating systems
function isValidFilename($value) {
return (strlen($value) <= 255 && preg_match('/^(?!^(PRN|AUX|CLOCK\$|NUL|CON|COM\d|LPT\d|\..*)(\..+)?$)[^\x00-\x1f\?*:"";|\/]+$/', $value) > 0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment