dlueth
6/27/2013 - 9:27 PM

PHP validator that checks if a given string is a valid/allowed filename across operating systems

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);
}