Broken filenames Broken filenames
 

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

Main Menu

Broken filenames

Started by Nightshader, December 23, 2004, 08:16:43 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Nightshader

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 =)

Joachim Müller

you're welcome - please post a link, so we can take a look.

Joachim

Nightshader

#2
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?

Nightshader

#3
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); # &#208;
   $string = ereg_replace(chr(192),chr(208).chr(144),$string); # &#192;
   $string = ereg_replace(chr(193),chr(208).chr(145),$string); # &#193;
   $string = ereg_replace(chr(194),chr(208).chr(146),$string); # &#194;
   $string = ereg_replace(chr(195),chr(208).chr(147),$string); # &#195;
   $string = ereg_replace(chr(196),chr(208).chr(148),$string); # &#196;
   $string = ereg_replace(chr(197),chr(208).chr(149),$string); # &#197;
   $string = ereg_replace(chr(168),chr(208).chr(129),$string); # &#168;
   $string = ereg_replace(chr(198),chr(208).chr(150),$string); # &#198;
   $string = ereg_replace(chr(199),chr(208).chr(151),$string); # &#199;
   $string = ereg_replace(chr(200),chr(208).chr(152),$string); # &#200;
   $string = ereg_replace(chr(201),chr(208).chr(153),$string); # &#201;
   $string = ereg_replace(chr(202),chr(208).chr(154),$string); # &#202;
   $string = ereg_replace(chr(203),chr(208).chr(155),$string); # &#203;
   $string = ereg_replace(chr(204),chr(208).chr(156),$string); # &#204;
   $string = ereg_replace(chr(205),chr(208).chr(157),$string); # &#205;
   $string = ereg_replace(chr(206),chr(208).chr(158),$string); # &#206;
   $string = ereg_replace(chr(207),chr(208).chr(159),$string); # &#207;
   $string = ereg_replace(chr(209),chr(208).chr(161),$string); # &#209;
   $string = ereg_replace(chr(210),chr(208).chr(162),$string); # &#210;
   $string = ereg_replace(chr(211),chr(208).chr(163),$string); # &#211;
   $string = ereg_replace(chr(212),chr(208).chr(164),$string); # &#212;
   $string = ereg_replace(chr(213),chr(208).chr(165),$string); # &#213;
   $string = ereg_replace(chr(214),chr(208).chr(166),$string); # &#214;
   $string = ereg_replace(chr(215),chr(208).chr(167),$string); # &#215;
   $string = ereg_replace(chr(216),chr(208).chr(168),$string); # &#216;
   $string = ereg_replace(chr(217),chr(208).chr(169),$string); # &#217;
   $string = ereg_replace(chr(218),chr(208).chr(170),$string); # &#218;
   $string = ereg_replace(chr(219),chr(208).chr(171),$string); # &#219;
   $string = ereg_replace(chr(220),chr(208).chr(172),$string); # &#220;
   $string = ereg_replace(chr(221),chr(208).chr(173),$string); # &#221;
   $string = ereg_replace(chr(222),chr(208).chr(174),$string); # &#222;
   $string = ereg_replace(chr(223),chr(208).chr(175),$string); # &#223;
   $string = ereg_replace(chr(224),chr(208).chr(176),$string); # &#224;
   $string = ereg_replace(chr(225),chr(208).chr(177),$string); # &#225;
   $string = ereg_replace(chr(226),chr(208).chr(178),$string); # &#226;
   $string = ereg_replace(chr(227),chr(208).chr(179),$string); # &#227;
   $string = ereg_replace(chr(228),chr(208).chr(180),$string); # &#228;
   $string = ereg_replace(chr(229),chr(208).chr(181),$string); # &#229;
   $string = ereg_replace(chr(184),chr(209).chr(145),$string); # &#184;
   $string = ereg_replace(chr(230),chr(208).chr(182),$string); # &#230;
   $string = ereg_replace(chr(231),chr(208).chr(183),$string); # &#231;
   $string = ereg_replace(chr(232),chr(208).chr(184),$string); # &#232;
   $string = ereg_replace(chr(233),chr(208).chr(185),$string); # &#233;
   $string = ereg_replace(chr(234),chr(208).chr(186),$string); # &#234;
   $string = ereg_replace(chr(235),chr(208).chr(187),$string); # &#235;
   $string = ereg_replace(chr(236),chr(208).chr(188),$string); # &#236;
   $string = ereg_replace(chr(237),chr(208).chr(189),$string); # &#237;
   $string = ereg_replace(chr(238),chr(208).chr(190),$string); # &#238;
   $string = ereg_replace(chr(239),chr(208).chr(191),$string); # &#239;
   $string = ereg_replace(chr(240),chr(209).chr(128),$string); # &#240;
   $string = ereg_replace(chr(241),chr(209).chr(129),$string); # &#241;
   $string = ereg_replace(chr(242),chr(209).chr(130),$string); # &#242;
   $string = ereg_replace(chr(243),chr(209).chr(131),$string); # &#243;
   $string = ereg_replace(chr(244),chr(209).chr(132),$string); # &#244;
   $string = ereg_replace(chr(245),chr(209).chr(133),$string); # &#245;
   $string = ereg_replace(chr(246),chr(209).chr(134),$string); # &#246;
   $string = ereg_replace(chr(247),chr(209).chr(135),$string); # &#247;
   $string = ereg_replace(chr(248),chr(209).chr(136),$string); # &#248;
   $string = ereg_replace(chr(249),chr(209).chr(137),$string); # &#249;
   $string = ereg_replace(chr(250),chr(209).chr(138),$string); # &#250;
   $string = ereg_replace(chr(251),chr(209).chr(139),$string); # &#251;
   $string = ereg_replace(chr(252),chr(209).chr(140),$string); # &#252;
   $string = ereg_replace(chr(253),chr(209).chr(141),$string); # &#253;
   $string = ereg_replace(chr(254),chr(209).chr(142),$string); # &#254;
   $string = ereg_replace(chr(255),chr(209).chr(143),$string); # &#255;
   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?