I need to save files with non-latin filenames on a filesytem, using PHP.
I want to make this work cross-platform. How do I know what encoding I can use to write the file? I understand many modern filesystems are UTF-8 based (is this correct?), but I doubt Windows XP is (for instance).
So, is there a robust detection mechanism?
Not an answer to your question, but if you don't need to do extensive operations on filesystem level (like searching, sorting...), there is a nice cross-platform workaround for the issue outlined in this SO question: URLEncode()
ing file names.
Hörensägen.txt
gets turned into
H%c3%b6rens%c3%a4gen.txt
which should be safe to use in any filesystem and is able to map any UTF-8 character.
I find this much preferable to trying to "natively" deal with the host OS's capabilities, which is guaranteed to be complicated and error-prone (in addition to operating system differences, I'm sure the various filesystem formats - FAT16, FAT32, NTFS, extFS versions 1/2/3.... bring their own set of rules to be aware of.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With