I 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?
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
When you upload file to web server, browser convert non unicode symbols in file name to UTF-8 (
нова-категория.png
becomesнова-категория.png
)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
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:
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.