0

enter image description hereI have this php function:

function upload_file($f,$fn){
switch($f['type']){
case 'image/jpeg':$image = imagecreatefromjpeg($f['tmp_name']);break;
case 'image/png':case 'image/x-png':move_uploaded_file($f['tmp_name'],'../images/pc/'.$fn.'.png');break;
case 'image/pjpeg':$image = imagecreatefromjpeg($f['tmp_name']);break;
echo $f['type'],'<br />';
}
if(!empty($image)) imagejpeg($image,'../images/pc/'.$fn.'.png');
}    

where $fn = "нова-категория" but when I upload the renamed file to server - the image name is broken and looks like this: РЅРѕРІР°-категория.png

The interesting thing is that if I try to visit the image on server: site.com/images/pc/нова-категория.png => I can see the image.. Can you give me an idea what brakes the image name to look normal?

Cœur
  • 37,241
  • 25
  • 195
  • 267
thecore7
  • 484
  • 2
  • 8
  • 29
  • Hey, I am deleting my answer because it does not solve your problem and a post with no answers will get more visibility. I am still monitoring the thread and as long as you notify me with `@Matt` I'll continue to try to help you. – Matt Jan 28 '14 at 14:42

1 Answers1

0
  1. When you browse ftp with ftp client you see ANSI-encoded names (single-byte encodings). In this case РЅРѕРІР°-категория.png is actually UTF-8 (double-byte) encoded нова-категория.png

  2. When you upload file to web server, browser convert non unicode symbols in file name to UTF-8 (нова-категория.png becomes РЅРѕРІР°-категория.png)

  3. When you request site.com/images/pc/нова-категория.png browser again convert non unicode symbols to UTF-8 and server actually looks for РЅРѕРІР°-категория.png (in ASCI-encoding).

So if you want to see "normal" names in ftp-client, you should convert them to your native encoding

function upload_file($f,$fn){
$fn=iconv("UTF-8","Windows-1251",$fn);
switch($f['type']){
...

But in this case you'll have problems with URLs to your files. To write correct URL to ANSI-encoded names you should use this php code:

echo "site.com/images/pc/".rawurlencode("нова-категория.txt");

The way you should handle file names is depends on your use of that files. But I don't recommend you to convert them. If you have problem, I thinks its not in "broken" names.

NekoNaz
  • 181
  • 6