Author Topic: Non-latin letters in file name  (Read 8856 times)

0 Members and 1 Guest are viewing this topic.

Offline k1lljoy

  • Jr. Member
  • **
  • Posts: 79
    • View Profile
    • Razruha.Ru
Non-latin letters in file name
« on: March 23, 2010, 10:24:08 PM »
I've stumbled upon one more issue...
If the image file, being uploaded, contains non-latin symbols (letters) - for instance, russian (cyrillic) letters, they would be omitted in the name of the uploaded image, for example:
best_фото_123.jpg will most likely turn into best__123.jpg

And if the file name contains just non-latin letters, without numerals and latin ones, then the uploader will get an error:

"Ошибка при загрузке фотографии:
.jpg: Неправильный формат файла (, image/jpeg)"  

which means, that the photo has a wrong format...  :|
And the photo won't be uploaded as well in that case, which is a bit disappointing  :?

Are there any possible solutions to this issue?  :roll:


Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: Non-latin letters in file name
« Reply #1 on: March 24, 2010, 02:09:25 AM »
This is a tricky situation. You can try replace in includes/upload.php
Code: (PHP) [Select]
     $this->file_name = preg_replace("/[^-\._a-zA-Z0-9]/", "", $this->file_name);
with this:
Code: (PHP) [Select]
     $this->file_name = preg_replace("/[^-\._a-zA-Z0-9а-яА-Я]/", "", $this->file_name);

I don't know if it works, because text on this forum is in unicode and your .php file is probably in different charset...anyway try to play with that line, I'm confident you'll understand what needs to be changed in that line ;) (just in case, a quick explanation what this line does: if filename contains characters that are not in that list - remove them)
« Last Edit: March 24, 2010, 02:26:56 AM by V@no »
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline k1lljoy

  • Jr. Member
  • **
  • Posts: 79
    • View Profile
    • Razruha.Ru
Re: Non-latin letters in file name
« Reply #2 on: March 24, 2010, 03:24:24 AM »
Thanks, Vano!

Hmm... I did those changes... Right now, when I'm trying tu upload a pic with an all-cyrillic name - I get some result:

"Warning: rename(.jpg,.jpg.bak) [function.rename]: No such file or directory in /var/www/razruha/data/www/razruha.ru/includes/annotate.php  on line 22"

and no result is displayed, just an empty space with the size of the image  :oops:

Although via ftp I can clearly see the uploaded file, albeit non-annotated.

But it's not displayed on the details page  :cry: dunno why

If we take a look on a source of the pic, it shows the correct place, where it actually is:
/data/media/Переход.jpg  or
/data/media/30/%D0%9F%D0%B5%D1%80%D0%B5%D1%85%D0%BE%D0%B4.jpg

but still not displayed on the page (

I already feel lots of difficulties with that issue  :oops:
Maybe there's some more simple way, for instance -  to rename non-latin names into smth on some particular basis?  :(


Offline alekseyn1

  • Full Member
  • ***
  • Posts: 102
    • View Profile
    • My Project
Re: Non-latin letters in file name
« Reply #3 on: October 29, 2010, 02:04:06 AM »
I gave up on this issue....
http://www.4homepages.de/forum/index.php?topic=27277.msg147707#msg147707


so I decided not to keep the original file names but to rename the pics on upload...
so in the includes upload.php

change
     $this->name = $regs[1];

to
      //$this->name = $regs[1];
     $this->name = time();

I think that was all I did... so now you should have your files named something like 1288274563.[extention]

I hope this helps

Offline bma2004

  • Newbie
  • *
  • Posts: 32
    • View Profile
Re: Non-latin letters in file name
« Reply #4 on: November 13, 2010, 01:22:05 PM »
This is a tricky situation. You can try replace in includes/upload.php
Code: (PHP) [Select]
     $this->file_name = preg_replace("/[^-\._a-zA-Z0-9]/", "", $this->file_name);
with this:
Code: (PHP) [Select]
     $this->file_name = preg_replace("/[^-\._a-zA-Z0-9а-яА-Я]/", "", $this->file_name);

I don't know if it works, because text on this forum is in unicode and your .php file is probably in different charset...anyway try to play with that line, I'm confident you'll understand what needs to be changed in that line ;) (just in case, a quick explanation what this line does: if filename contains characters that are not in that list - remove them)

RU
Столкнулся с такой же проблемой. Проблема в том, что если тип файла написан БОЛЬШИМИ буквами, то 4images отказывается принять такой файл и сообщает, что "неправильный формат"

EN
Faced with the same problem. The problem is that if the file type in capital letters, then 4images refuses to accept the file and reports that "incorrect format"

Offline V@nо

  • Addicted member
  • ******
  • Posts: 1.223
    • View Profile
Your first three "must do" before you ask a question:
If I asked you to PM me, I meant PM to my primary account, this account doesn't accept PMs.

Offline bma2004

  • Newbie
  • *
  • Posts: 32
    • View Profile
Re: Non-latin letters in file name
« Reply #6 on: November 16, 2010, 08:46:18 AM »
Thanks!