PHP Unicode文件名

3

PHP无法处理带有Unicode字符的文件:当我在浏览器中访问testSite/главная.php时,它会抛出以下错误。

警告:Unknown: failed to open stream: No such file or directory in Unknown on line 0

致命错误:Unknown: Failed opening required 'blah/blah/testSite/главнаÑ.php' (include_path='.;C:\xampp\php\pear\') in Unknown on line 0

然而,testSite/главная.html没有问题。

是否有任何方法可以解决这个问题,或者我必须使用另一种能更好处理Unicode的编程语言?

Apache htdocs in folder with unicode name


使用非纯ASCII文件名,使用空格作为文件名就像是在自找麻烦。一定要避免。请给自己一个方便,放弃这个坏习惯。 - Marcin Orlowski
我理解,但我没有更改文件名的选项。我必须利用手头的资源工作。 - Tristanisginger
不可能实现。原因在于:https://dev59.com/x3RB5IYBdhLWcg3wJUau#16941794 - Tristanisginger
5个回答

0

也许它有效:

mb_internal_encoding('UTF-8');
ini_set('default_charset', 'UTF-8');

0

使用Unicode文件名打开php文件不是php的问题,而是取决于底层操作系统。只要操作系统支持Unicode文件名,它就可以工作。

在我的Debian Squeeze上,这根本不是问题,在Windows 7(NetBeans运行的地方)创建一个名为главная.php的文件也没有问题:

include 'главная.php';

enter image description here


我已经创建了文件,在服务器上运行它时出现故障。 - Tristanisginger
我正在本地的winXP上运行它,使用xammp。 - Tristanisginger

0

0

看起来,你的 Web 服务器在 URI 中使用 win-1252 编码。 尝试在你的 Apache/Nginx/任何配置中设置 utf-8。 如果只在 require()/include() 上下文中使用 Unicode 名称,你也可以使用 iconv()/mb_convert_encoding() 进行编码转换。


那为什么testSite/главная.html没问题呢? - Tristanisginger

0

在PHP5中使用"wfio://"

https://github.com/kenjiuno/php-wfio

对于文件夹访问,请使用以下方法:

.htaccess:

php_value auto_prepend_file C:/fix.php

fix.php:

$file = $_SERVER['SCRIPT_FILENAME'];
if (!is_readable($file)) {
    $file="wfio://".$file;
                include $file;
                exit;
        }

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接