Faced with the need to check the uploaded file name and its variations in the event of incorrect names. In my case, many do not read the rules and write the name in the Cyrillic alphabet, and it is necessary to write in Latin. How to solve it you have two options, but for some reason they do not work, maybe I'm doing something wrong, because my knowledge of php is not very large.
The first code to validate that if there are Russian letters in the name will generate an error:
The second option is to do a transliteration (option "Random name" does not fit, as needed source name):
I would be very grateful for your help, because he could not figure out what kind of settings in the plugin phpvalidations need to put these techniques to work?
The first code to validate that if there are Russian letters in the name will generate an error:
PHP:
if(!preg_match('#[^a-z0-9_\-\. ]#ui', $name)){
if(strlen($name) == 0){//Checking the name are blank
$error[] = 'Fill out the field <b>Files</b>';
}
else{
$error[] = 'The file name is used Cyrillic';
}
}
The second option is to do a transliteration (option "Random name" does not fit, as needed source name):
PHP:
unction remove_shit($name) {
static $table = array(
'?' => 'a',
'?' => 'b',
'?' => 'v',
...
'?' => 'A',
'?' => 'B',
'?' => 'V',
...
);
return preg_replace('#[^-._a-z0-9]#ui', '', strtr($name, $table));
}
I would be very grateful for your help, because he could not figure out what kind of settings in the plugin phpvalidations need to put these techniques to work?