function _services_file_check_name in Services 7.3
Sanitizes a user-input file or directory name.
Parameters
string $name: The file or directory name.
Return value
string A safe name.
1 call to _services_file_check_name()
- _services_file_check_name_extension in resources/
file_resource.inc - Sanitizes a user-input file name and extension.
1 string reference to '_services_file_check_name'
- _services_file_check_destination in resources/
file_resource.inc - Sanitizes a user-input file path, name and extension.
File
- resources/
file_resource.inc, line 500 - File resource.
Code
function _services_file_check_name($name) {
// Punctuation characters that are allowed, but not as first/last character.
$punctuation = '-_. ';
$map = array(
// Replace (groups of) whitespace characters.
'!\\s+!' => ' ',
// Replace multiple dots.
'!\\.+!' => '.',
// Remove characters that are not alphanumeric or the allowed punctuation.
"![^0-9A-Za-z{$punctuation}]!" => '',
);
// Apply the regex replacements. Remove any leading or hanging punctuation.
return trim(preg_replace(array_keys($map), array_values($map), $name), $punctuation);
}