Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I am getting a file with a faroese name and trying to save it in a PHP script:

2010_08_Útflutningur.xls

In Ubuntu 10.04 LTS is saving it as:

2010_08_�tflutningur.xls (invalid encoding)

I've installed and run utf8-migration-tool, but with no effect.

Is this an Ubuntu error that I can fix or I just have to give up and modify the name in php?

Is there a document which states what is the acceptable charset for a filename in Ubuntu, or what are the encoding specs?

Thanks

share|improve this question
    
How are you receiving and saving the file via PHP? (What does the code look like?) –  Kees Cook Oct 26 '10 at 14:17
    
I was parsing it from an email system. The code is complex :) –  Elzo Valugi Oct 27 '10 at 6:44
    
There is a similar Q&A with a script to repair broken filenames. –  lumbric Mar 17 '12 at 11:09

2 Answers 2

up vote 4 down vote accepted

This looks like an encoding issue. Unfortunately, PHP needs a bit of hand-holding when it comes to encodings, because its strings are single-byte by default. If you are creating the filename within PHP, utf8_encode() should be helpful; note, however, that it assumes ISO-8859-1 encoding for the input.

On the other hand, if you are using the filename submitted by a client, perhaps you can request the the client do the encoding for you. That is done with the accept-charset attribute of the <form> tag, and/or by setting the charset of the page that the form is on. Certain clients may use one or the other, so for best results use UTF-8 for each.

share|improve this answer
    
Yeap. Thanks to both of you –  Elzo Valugi Oct 27 '10 at 6:43

By default Ubuntu uses UTF-8 for filenames. Most modern linux distros and many other operating systems do so (Windows/NTFS is the best known exception with UTF-16).

To fix files that have names in the wrong encoding like the one you show, you can try to use nautilus-filename-repairer Install nautilus-filename-repairer.

You can use the PHP iconv functions to convert strings (filenames) from one encoding to the other. Of course that requires that you know what encoding they are in to begin with.

To get correctly encoded filenames from the client, you can try the technique explained by eswald.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.