[SOLVED]Almost ready solution with Cyrillic in the name of the file

Status
Not open for further replies.

GorYa

Member
Because through the form of frequently downloaded files, then write the name of some Latin, Cyrillic and others, but does not take an element of the Cyrillic alphabet. I decided to read this issue properly. The file filesystemstorage.php replaced
Code:
$filename = preg_replace('#[^a-zA-Z0-9_\-\.]#', '_', $filename);

on
Code:
$filename = preg_replace('#[^a-zA-Z0-9?-??-???_\-\.]#u', '_', $filename);

Everything works fine, downloaded files with names like in Latin and Cyrillic. But the names on Cyrillic have a problem, when you send the mail, and when displayed on the front End he cuts the first word, then there was "my work" to become "_work". This situation only with the Cyrillic alphabet with the Latin names of all good. Files with names in Cyrillic remarkably saved on the server and displayed correctly when editing entries.

if you write the name of the file "Latin Cyrillic", then come in the form of a normal "Latin_Cyrillic", not only takes up the first letters of the space Cyrillic. Perhaps in a certain script, you must also add the Cyrillic alphabet in the regular expression

Tell me what went wrong.
 
Last edited:
Shorten the expression and it works, but also the situation, removes the first word before the space
Code:
$filename = preg_replace('#[^\w\d_\-\.]#iu', '_', $filename);
that is, instead of "my work" becomes "_work"

The error only appears on the Front End and when sending files by mail. In all other cases, all is well and in the database and on the server files have the full name. While I can not understand what is responsible for the output file name cropped

Tell me where to look for the cause?
 
Last edited:
$filename = preg_replace('#[^\w\d_\-\.]#iu', '_', $filename);

seems to do fine on my site.
string(20) "??????, ???"
becomes
string(20) "??????__???"

You can add
var_dump($filename);exit;
to see what you get.

Maybe the string is cut in a later step?
 
This only happens with the names in the Cyrillic alphabet, the first word is displayed at the display in the Front-End. For example (I quote in English): "My work is progressing" on the screen and in the preparation of the letter file name becomes "_work_is_progressing". With all the recognized file names written in the Latin alphabet as it should
 
I only tested the preg_replace (var_dump $filename directly before and after).
I assume this is Cyrillc;)
vor:
string(44) "??? ?????? ????????????"
nach:
string(44) "???_??????_????????????"

Maybe the string is cut in a later step?
 
Cyrillic is all right:) When checking for php me and all is well. Like would not change anything else, it is possible that the changes in prescribed function after this line
Code:
 public function cleanName($filename, $repeatCounter)
    {
// Replace any non-alphanumeric chars (except _ and - and .) with _
$filename = preg_replace('#[^\w\d_\-\.]#iu', '_', $filename);
$this->randomizeName($filename);

return $filename;
}

maybe the whole thing in the function "randomizeName", but not sure, because I do not know much in php
 
Last edited:
Example error with the output of Cyrillic:
1. The form displays all right
example2.jpg
2. A table and attachments mail Cyrillic removes the first word
example1.jpg
 
Last edited:
possibly - if you turn off the option does the text look ok?
If so can one of you create a PR and I'll commit the change
Thanks!
 
If you remove the function "randomizeName", it still lost the first word in the names of the Cyrillic alphabet, try to upgrade to version 5.6 php. This error may only me :(
 
Last edited:
As far as I can see "randomizeName" is only doing anything if "obscurify" is enabled.
$filename is unchanged after randomizeName.
I assume the filenames are touched elsewhere, too.
 
Solved. With minor modifications filesystemstorage.php can now add files with names in Russian and English (that is, both the Latin and Cyrillic)
 
Last edited:
Can you share your solution?


To file names could be attached both in Russian and in English (in Cyrillic or Latin alphabet) must be in the file filesystemstorage.php row 191
Code:
$filename = preg_replace('#[^a-zA-Z0-9_\-\.]#', '_', $filename);
replaced by (recommended)
Code:
$filename = preg_replace('#[^a-zA-Z0-9?-??-???_\-\.]#u', '_', $filename);
or (shorter code)
Code:
$filename = preg_replace('#[^\w\d_\-\.]#iu', '_', $filename);

but if you just change the code in line 191, the file names written in the Cyrillic alphabet will be truncated first word. To this was not necessary immediately after the line 1, insert the following code
Code:
setlocale(LC_ALL, 'ru_RU.utf8');

Also translated the words and sentences in addition to Russian localization required for the normal operation of a upload element.

Modified files enclose attachments. I would be glad if these changes will be made to the component authors (of course after checking) in the source code element, because after each update, you have to manually change all.
 

Attachments

  • mod_files.zip
    10 KB · Views: 251
Last edited:
Thanks. I think it does not affect other files, especially on something else, but still it needs to be tested and the decision is made by you.
Tested on the following formats (which allowed me): doc, docx, jpg, tif, tiff, cdr, pdf, zip
I think that other formats will be no problems
screens enclose
list
1.jpg

the form
2.jpg

ftp
3.jpg
 
Last edited:
Status
Not open for further replies.
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top