Greetingzz :-)
I have a trouble with files which have national (russian-language) characters in filenames. All is ok with files that contain only english characters in name, but when i upload russian-name files there is a trouble.
Server succesfully receives the file and places it in right directory, but when i try to see this file in gallery i receive "image cannot be found" - only redcross and placeholder are shown (this concerns both thumbnail, normal_ and original images).
When i try to go to hyperlink of picture i receive FORBIDDEN and *wrong-encoded* non-original filename of picture in error report (russian characters are encoded to %xx url-replacements, but when i paste this string to browser it returns wrong decoded russian-chars).
Alt text of thumblail and title of image are normal, also filename showing in fileinfo is normall too.
What this can be? Web-server or coppermine? Does anybody have something like this? And what info i must provide?
Really big THANX for great work to all people who take part in CPG development!
Sorry for my bad eng =)
you're welcome - please post a link, so we can take a look.
Joachim
Webserver with my gallery is in lan and doesn't have an internet connection =(
I began an investigation and discovered that image names being encoded into hex-representations of ascii chars (russian windows-1251 charset, i knew it erlier but hasn't made attention) but the browser thinks that URLs are utf-8 encoded and interpreters chars as hex-encoded UTF-8-chars -> decodes filenames into UTF-8, which results in wrong filenames (wrong utf-8 character with same number replaces right ascii char).
So as i think, there is an "coppermine (mysql stores russian data as windows-1251 too?) url-encoding as ascii (webserver returns ascii-encoded urls)" <-> "browser url-decoding as utf-8" trouble.
I can't use disabling "Always send URLS as utf-8" option (and does this have a mention anyway?) and have many users uploading imgs with russian filenames to gallery so i wonder if there are none-client-side solutions for this trouble (an utf-8 url encoding for example)?
***Apache and php have windows-1251 encoding as default.***
Thanx for your support! :)
=====adding=====
is this right to encode windows-1251 filenames in url into utf-8 and then encode those utf-8-filename-urls with urlencode?
So i found a solution (i don't know if it is right, i need your advice about this =)) - encoding URLs into utf-8 before rawurlencode.
Changes i made (CPG 1.3.2)
In
functions.inc.php:
Found
Quote// Function to create correct URLs for image name with space or exotic characters
function path2url($path)
and inserted before this lines new function
Quote// Function to convert windows-1251 chars into utf-8
function win1251_to_utf8($string)
{
$string = ereg_replace(chr(208),chr(208).chr(160),$string); # Ð
$string = ereg_replace(chr(192),chr(208).chr(144),$string); # À
$string = ereg_replace(chr(193),chr(208).chr(145),$string); # Á
$string = ereg_replace(chr(194),chr(208).chr(146),$string); # Â
$string = ereg_replace(chr(195),chr(208).chr(147),$string); # Ã
$string = ereg_replace(chr(196),chr(208).chr(148),$string); # Ä
$string = ereg_replace(chr(197),chr(208).chr(149),$string); # Å
$string = ereg_replace(chr(168),chr(208).chr(129),$string); # ¨
$string = ereg_replace(chr(198),chr(208).chr(150),$string); # Æ
$string = ereg_replace(chr(199),chr(208).chr(151),$string); # Ç
$string = ereg_replace(chr(200),chr(208).chr(152),$string); # È
$string = ereg_replace(chr(201),chr(208).chr(153),$string); # É
$string = ereg_replace(chr(202),chr(208).chr(154),$string); # Ê
$string = ereg_replace(chr(203),chr(208).chr(155),$string); # Ë
$string = ereg_replace(chr(204),chr(208).chr(156),$string); # Ì
$string = ereg_replace(chr(205),chr(208).chr(157),$string); # Í
$string = ereg_replace(chr(206),chr(208).chr(158),$string); # Î
$string = ereg_replace(chr(207),chr(208).chr(159),$string); # Ï
$string = ereg_replace(chr(209),chr(208).chr(161),$string); # Ñ
$string = ereg_replace(chr(210),chr(208).chr(162),$string); # Ò
$string = ereg_replace(chr(211),chr(208).chr(163),$string); # Ó
$string = ereg_replace(chr(212),chr(208).chr(164),$string); # Ô
$string = ereg_replace(chr(213),chr(208).chr(165),$string); # Õ
$string = ereg_replace(chr(214),chr(208).chr(166),$string); # Ö
$string = ereg_replace(chr(215),chr(208).chr(167),$string); # ×
$string = ereg_replace(chr(216),chr(208).chr(168),$string); # Ø
$string = ereg_replace(chr(217),chr(208).chr(169),$string); # Ù
$string = ereg_replace(chr(218),chr(208).chr(170),$string); # Ú
$string = ereg_replace(chr(219),chr(208).chr(171),$string); # Û
$string = ereg_replace(chr(220),chr(208).chr(172),$string); # Ü
$string = ereg_replace(chr(221),chr(208).chr(173),$string); # Ý
$string = ereg_replace(chr(222),chr(208).chr(174),$string); # Þ
$string = ereg_replace(chr(223),chr(208).chr(175),$string); # ß
$string = ereg_replace(chr(224),chr(208).chr(176),$string); # à
$string = ereg_replace(chr(225),chr(208).chr(177),$string); # á
$string = ereg_replace(chr(226),chr(208).chr(178),$string); # â
$string = ereg_replace(chr(227),chr(208).chr(179),$string); # ã
$string = ereg_replace(chr(228),chr(208).chr(180),$string); # ä
$string = ereg_replace(chr(229),chr(208).chr(181),$string); # å
$string = ereg_replace(chr(184),chr(209).chr(145),$string); # ¸
$string = ereg_replace(chr(230),chr(208).chr(182),$string); # æ
$string = ereg_replace(chr(231),chr(208).chr(183),$string); # ç
$string = ereg_replace(chr(232),chr(208).chr(184),$string); # è
$string = ereg_replace(chr(233),chr(208).chr(185),$string); # é
$string = ereg_replace(chr(234),chr(208).chr(186),$string); # ê
$string = ereg_replace(chr(235),chr(208).chr(187),$string); # ë
$string = ereg_replace(chr(236),chr(208).chr(188),$string); # ì
$string = ereg_replace(chr(237),chr(208).chr(189),$string); # í
$string = ereg_replace(chr(238),chr(208).chr(190),$string); # î
$string = ereg_replace(chr(239),chr(208).chr(191),$string); # ï
$string = ereg_replace(chr(240),chr(209).chr(128),$string); # ð
$string = ereg_replace(chr(241),chr(209).chr(129),$string); # ñ
$string = ereg_replace(chr(242),chr(209).chr(130),$string); # ò
$string = ereg_replace(chr(243),chr(209).chr(131),$string); # ó
$string = ereg_replace(chr(244),chr(209).chr(132),$string); # ô
$string = ereg_replace(chr(245),chr(209).chr(133),$string); # õ
$string = ereg_replace(chr(246),chr(209).chr(134),$string); # ö
$string = ereg_replace(chr(247),chr(209).chr(135),$string); # ÷
$string = ereg_replace(chr(248),chr(209).chr(136),$string); # ø
$string = ereg_replace(chr(249),chr(209).chr(137),$string); # ù
$string = ereg_replace(chr(250),chr(209).chr(138),$string); # ú
$string = ereg_replace(chr(251),chr(209).chr(139),$string); # û
$string = ereg_replace(chr(252),chr(209).chr(140),$string); # ü
$string = ereg_replace(chr(253),chr(209).chr(141),$string); # ý
$string = ereg_replace(chr(254),chr(209).chr(142),$string); # þ
$string = ereg_replace(chr(255),chr(209).chr(143),$string); # ÿ
return $string;
}
then i added the new string (which calls to previously added function) before this string
Quotereturn str_replace("%2F","/",rawurlencode($path));
}
this new string is
Quote$path = win1251_to_utf8($path);
So changed path2url function is
Quote// Function to create correct URLs for image name with space or exotic characters
function path2url($path)
{
$path = win1251_to_utf8($path);
return str_replace("%2F","/",rawurlencode($path));
}
That is all the changes i made. Everything seems to be ok - now pictures with russian filenames are shown. Is my code correct? Functions
get_pic_url and
path2url are only used when displaying images, right?