Pavenhimself
Pavenhimself

Reputation: 567

Server problems with æ ø å

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.

Upvotes: 3

Views: 1477

Answers (3)

larsmqller
larsmqller

Reputation: 21

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;
}

Upvotes: 1

classicjonesynz
classicjonesynz

Reputation: 4042

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

Upvotes: 2

Ren&#233; H&#246;hle
Ren&#233; H&#246;hle

Reputation: 27325

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

Upvotes: 5

Related Questions