Reputation: 567
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
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', // Æ to Ae
chr(195).chr(166) => 'ae', // æ to ae
chr(195).chr(152) => 'OE', // Ø to OE
chr(195).chr(184) => 'oe', // ø to oe
chr(195).chr(133) => 'AA', // Å to AA
chr(195).chr(165) => 'aa' // å to aa
);
$translated = strtr($filename,$filter_chars); // Translate characters
return $translated;
}
Upvotes: 1
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
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