3

I have a UNIX server running. I have a program, that uploads images to my server.

but I'm having some problems with these chars: ø æ å

In my program I used

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

Example:

I upload an image called påske.png

On my server I can see the picture is called påske.png

In my database, the name påske.png is also saved.

if I then manually tries to see my picture, I get an error

I type: www.myserver.com/uploads/påske.png

Error: /uploads/påske.png was not found on this server.
Picrofo Software
  • 5,475
  • 3
  • 23
  • 37
Pavenhimself
  • 527
  • 1
  • 5
  • 18

3 Answers3

5

You shoulnd't save the special chars direct as filename. Give them a new name like a timestamp or replace the spacial chars with the english equivalent.

What you have is normal then your server / Webserver has a default charset like UTF-8 for example. Special chars in Linux are displayed in this character Set.

Edit:

Replace special characters before the file is uploaded using PHP

Community
  • 1
  • 1
René Höhle
  • 26,716
  • 22
  • 73
  • 82
  • Thanks for the reply and the advice. I think I will follow it. I tried this: $overskrift_tmp = preg_replace("/[^a-zA-Z0-9]/", "", $overskrift);. When I type in: etætoøtreå. I get this: etaeligtooslashtrearing. Can't i just get ettotre ? – Pavenhimself Nov 02 '12 at 09:24
  • Okay, the admin of my server told me just to avoid æ ø å, so I am using your suggestion :) Thank you – Pavenhimself Nov 02 '12 at 10:00
2

Alternatively you could use this class and change the file name during upload

* normal - converts each special character (áéíÁÈÒÖ) to their 
normal character (aeiAEOO)

string $class->normal(string string);

Example: 
print $strings->normal("faço áeéíàÒ");
# will output: faco aeeiaO
classicjonesynz
  • 4,012
  • 5
  • 38
  • 78
1

Try this.

function de_danishify_filename_on_upload($filename) {
if("do a check") return $filename; // Checks to see if a string is utf8 encoded

$filter_chars = array(
    // Character mapping from UTF-8 characters to ASCII characters. 
    chr(195).chr(134) => 'AE',  // &AElig; to Ae
    chr(195).chr(166) => 'ae',  // &aelig; to ae
    chr(195).chr(152) => 'OE',  // &Oslash; to OE
    chr(195).chr(184) => 'oe',  // &oslash; to oe
    chr(195).chr(133) => 'AA',  // &Aring; to AA
    chr(195).chr(165) => 'aa'   // &aring; to aa
);
$translated = strtr($filename,$filter_chars); // Translate characters

return $translated;
}
larsmqller
  • 21
  • 5