0

When I'm uploading in CMS files with cyrillic names, cyrillic symbols just disappears. For example: filename "мой_файл.txt" becomes just "txt" without "мой_файл." Filename has windows-1251 encoding.

Firebug shows :

POST /admin/projects/Project/EditForm/field/Project/item/6/ItemEditForm/field/Projects/upload HTTP/1.1
Host: silver.rivreg.ru
User-Agent: Mozilla/5.0 (Windows NT 6.3; rv:46.0) Gecko/20100101 Firefox/46.0
Accept: application/json, text/javascript, */*; q=0.01
Accept-Language: ru-RU,ru;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
X-Requested-With: XMLHttpRequest
Referer: http://silver.rivreg.ru/admin/projects/Project/EditForm/field/Project/item/6/edit
Content-Length: 377
Content-Type: multipart/form-data; boundary=---

And at the Post tab shows:

Content-Disposition: form-data; name="SecurityID"
4754dec1aad707dd63e8cc58c8e469d0bc149425
-----------------------------81762142719766
Content-Disposition: form-data; name="Projects[Uploads][]"; filename="мой_Ñайл.txt"**
Content-Type: text/plain
ïîëïîïîïîïîïîïîîûûûûûûû
-----------------------------81762142719766--

Please give me any help.

alex
  • 307
  • 1
  • 13

1 Answers1

1

Have a look at FileNameFilter as this is the logic that "cleans-up" incoming / uploaded filenames.

Specifically look at its $default_replacements private (config) static. Because it's private static, it can be modified in userland (custom) YML config.

The relevant line is even commented for you:

// remove non-ASCII chars, only allow alphanumeric plus dash and dot

Override this in your own custom YML config with something that suits the range of characters that your system will accept.

theruss
  • 1,690
  • 1
  • 12
  • 18
  • I added to config.yml `FileNameFilter: default_use_transliterator: false default_replacements:` , cleared the cache manifest (flush=all) and recieved `Warning: Invalid argument supplied for foreach() in /usr/home/smolin/silver/framework/core/manifest/ConfigManifest.php on line 655`. The behavior of FileNameFilter did not change – alex May 31 '16 at 07:55
  • The same situation as in [this post](http://stackoverflow.com/questions/36944404/silverstripe-3-1-change-filenamefilter-default-replacements) – alex May 31 '16 at 08:01
  • If you really defined `default_replacements` without anything to its right, then that error is almost definitely SPL failing to parse your invalid YML. You need to *substitute* the ASCII-specific entry found in core's `FileNameFilter` with your own regex based on the requirements of your system (i.e. to include cyrillic characters). All you've done is redefine the `default_replacements` array as "empty" and cause a PHP error. – theruss May 31 '16 at 08:59
  • From this point on, your problem is almost certainly no longer a SilverStripe problem, but a regex problem. With that in mind, see [this post](http://stackoverflow.com/questions/1716609/how-to-match-cyrillic-characters-with-a-regular-expression) with regard to matching Cyrillic characters. – theruss May 31 '16 at 09:03
  • It seems to me I don't understand YML syntax. I used YML file from [FileNameFiter](http://api.silverstripe.org/3.1/class-FileNameFilter.html). But it does't work. Please, can you explain for dummy the YML file structure in this specific case? – alex Jun 01 '16 at 06:28
  • When I use brute force i.e. edit file framework/filesystem/FileNameFilter.php and insert `private static default_replacements = array();` all cyrillic names files upload normally. But it's wrong way – alex Jun 01 '16 at 06:36
  • Hi Alex, there are 2 ways of creating/updating SS config: 1 using private static variables (arrays, scalars etc) defined _in the class itself_ 2. YML. For YML open up your project's own YML config file which is: `mysite/_config/config.yml` and copy/paste the contents of the following gist into it: https://gist.github.com/phptek/9bfc7358191c67827be88f1a817c89d9 All this is, is the contents of `FileNameFilter::$default_replacements` converted to YML. [see here](https://docs.silverstripe.org/en/3.3/developer_guides/configuration/configuration/) you will still need to make your mods to it. – theruss Jun 01 '16 at 08:32
  • Thank you TheRuss for help! I understood. – alex Jun 01 '16 at 10:42
  • Glad I helped, but helped you learn a little too. And seeing as my original answer helped you, please consider accepting it as "the" answer. – theruss Jun 01 '16 at 18:07