PHP检测具有非拉丁文件名的文件系统编码/保存文件 [英] PHP detecting filesystem encoding/saving files with non-latin filenames

查看:88
本文介绍了PHP检测具有非拉丁文件名的文件系统编码/保存文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用PHP将具有非拉丁文件名的文件保存在文件系统中.

I need to save files with non-latin filenames on a filesytem, using PHP.

我想使这项工作跨平台.我怎么知道我可以使用哪种编码来写文件?我了解许多现代文件系统都是基于UTF-8的(对吗?),但是我怀疑Windows XP是(例如).

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 

变成了

H%c3%b6rens%c3%a4gen.txt

应该可以在任何文件系统中安全使用,并且能够映射任何UTF-8字符.

which should be safe to use in any filesystem and is able to map any UTF-8 character.

我发现这比尝试本机"处理主机操作系统的功能要好得多,因为这肯定很复杂且容易出错(除了操作系统差异外,我敢肯定各种文件系统格式-FAT16, FAT32,NTFS,extFS版本1/2/3 ....带来了自己需要注意的一组规则.)

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.)

这篇关于PHP检测具有非拉丁文件名的文件系统编码/保存文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆