函数代码
function is_valid_filename($name) { $parts = preg_split("/(\/|".preg_quote("\\").")/", $name); if (preg_match("/[a-z]:/i", $parts[0])) { unset($parts[0]); } foreach ($parts as $part) { print "part = '$part'
"; if (preg_match("/[".preg_quote("^|&#63;*<\":>", "/")."\a\b\c\e\x\v\s]/", $part) || preg_match("/^(PRN|CON|AUX|CLOCK$|NUL|COMd|LPTd)$/im", str_replace(".", "\n", $part))) { return false; } } return true; } $bad = array_merge(array_map('chr', range(0, 31)), array("<", ">", ":", '"', "/", "\\", "|", "&#63;", "*")); $result = str_replace($bad, "", $filename);
windows 系统文件命名规则限制
https://msdn.microsoft.com/en-us/library/aa365247