The problem is this: my program gets the file from the user. I change all spaces like this: $p = str_ireplace(' ', '_', $_FILES['filename']['name']); .

Next, the file is saved under the name $p . As a result, the file is saved with the following name: Р'ерн_Жюль._20_000_лье_РїРѕРґ_РІРѕРґРѕР№.fb2 . I know that this is because of the encoding, because $_FILES['filename']['name'] = 'Верн Жуль. 20 000 лье под водой $_FILES['filename']['name'] = 'Верн Жуль. 20 000 лье под водой . Tell me, please, how to fix it!

  • Save the real file name and pseudonym in Latin in the database, and write the file to the system under this pseudonym or even under the sequence number. - Visman
  • You need to recode the name from the incoming encoding (utf-8) to the encoding of the file system. For * nix this is koi-8 for Win Ansi encoding for the current code page - Anton Shchyrov

1 answer 1

Try this feature:

 function chpu ($path){return strtr($path,array("«"=>"", "»"=>"", " "=>"_", "-"=>"_", "№"=>"", "є"=>"e", "і"=>"i", "І"=>"i", "$"=>"", ";"=>"", ":"=>"", ","=>"", "."=>"", "["=>"", "'"=>"", "]"=>"", "*"=>"_", "/"=>"_", "|"=>"_", "{"=>"", "}"=>"", "="=>"_", "+"=>"", "?"=>"", "!"=>"", "@"=>"", "#"=>"", "%"=>"", "^"=>"", "&"=>"", "("=>"", ")"=>"", "\""=>"", "а"=>"a", "б"=>"b", "в"=>"v", "г"=>"g", "д"=>"d", "е"=>"e", "ё"=>"jo", "ж"=>"zh", "з"=>"z", "и"=>"i", "й"=>"j", "к"=>"k", "л"=>"l", "м"=>"m", "н"=>"n", "о"=>"o", "п"=>"p", "р"=>"r", "с"=>"s", "т"=>"t", "у"=>"u", "ф"=>"f", "х"=>"x", "ц"=>"c", "ч"=>"ch", "ш"=>"sh", "щ"=>"shh", "ъ"=>"", "ы"=>"y", "ь"=>"", "э"=>"je", "ю"=>"ju", "я"=>"ya", "йо"=>"j/o", "йе"=>"j/e", "А"=>"a", "Б"=>"b", "В"=>"v", "Є"=>"e", "Г"=>"g", "Д"=>"d", "Е"=>"e", "Ё"=>"jo", "Ж"=>"zh", "З"=>"z", "И"=>"i", "Й"=>"j", "К"=>"k", "Л"=>"l", "М"=>"m", "Н"=>"n", "О"=>"o", "П"=>"p", "Р"=>"r", "С"=>"s", "Т"=>"t", "У"=>"u", "Ф"=>"f", "Х"=>"x", "Ц"=>"c", "Ч"=>"ch", "Ш"=>"sh", "Щ"=>"shh", "Ъ"=>"", "Ы"=>"y", "Ь"=>"", "Э"=>"je", "Ю"=>"ju", "Я"=>"ya", "ЙО"=>"", "ЙЕ"=>"")); } 

Once I used it to form CNC from the title of the article, but for you it can also be suitable.

 $p = chpu($_FILES['filename']['name']); 

The name chpu can be changed to your own :)

  • Why are ЙО and ЙЕ replaced by void (deleted) when йо and йо are replaced by j/o and j/e ? Why is the strange choice of replacing j with j instead of y ? It is clear that you are so comfortable, but it seems like a replacement for y is accepted everywhere. What is the symbol Є ?)) - DaemonHK