问题
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 if the multi-byte characters can be written into database then can be read out, then why it fails when it is renamed ?
回答1:
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.
回答2:
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.
回答3:
This Sample Should Helps , You Should Find Your Language Code Page And Replace With That. I Test Bellow Code And It Works In Windows For Arabic/Persian Names:
$newname = iconv("utf-8", "cp1256","گچپژ");
echo rename("1.txt", $newname);
回答4:
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.
来源:https://stackoverflow.com/questions/873853/rename-not-supporting-multi-byte-characters