views:

302

answers:

4

If I write:

rename('php109.tmp','test.jpg');

then it's fine and working.

but if I change it into:

rename('php109.tmp','中文.jpg');

it'll report "No such file or directory...".

But the multi-byte characters can be written into database then read out fine,

why it fails when towards rename ?

A: 

I have installed PHP mbstring extension and I don't have any problems renaming files with multibyte characters in their names. make sure this extension is installed loaded in runtime.

farzad
no,now I doubt that rename or other file system operating functions uses the encoding of file system.Because my file system is not utf8,so ...
Shore
I am sure now that rename uses the same encoding set as file system!But don't know how to change that!
Shore
can you tell us what filesystem you are using? after all if your filesystem does not support multibyte characters, I'm not sure if you can rename your files to multibyte names anyway. maybe you could map their non-multibyte names on the filesystem, to multibyte names in your database.
farzad
A: 

I'm almost sure that the mbstring has nothing to do with this specific problem, I think the problem here relies on the encoding of your .php file.

Try changing the encoding of the file to UTF-8 (no BOM!) in your code editor.

Alix Axel
but the file is already utf8 encoded..
Shore
A: 

File systems do not necessarily use UTF-8. For instance, this is what Wikipedia says about NTFS:

NTFS allows any sequence of 16-bit values for name encoding (file names, stream names, index names, etc.). This means UTF-16 codepoints are supported, but the file system does not check whether a sequence is valid UTF-16 (it allows any sequence of short values, not restricted to those in the Unicode standard).

You might need to use iconv() to convert between charsets.

Álvaro G. Vicario
A: 

Did you try doing a setlocale(LC_ALL, array("es_ES.utf-8","es_ES@euro",'es_ES')); or whatever your country code is, to make sure the locale is set correctly?

If this call does not return something with 'utf-8' in it, it means it failed and will then return the current locale.

jfoucher