Linux中带有重音符号的scandir问题在OSX中可以正常工作 [英] scandir issue with accents in Linux work fine in OSX

查看:92
本文介绍了Linux中带有重音符号的scandir问题在OSX中可以正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我使用下一个功能在我的网站中创建树形目录菜单,该目录包含许多pdf和excel,有时此文件的名称带有重音符号,空格和ñ,我的应用程序在OSX中可以完美运行(mac ),但不久我就在我的Godaddy服务器(Linux)中上传了,所有带有重音符号的字符都被替换为?字符的字符打破了所有名称和链接.您知道该如何处理吗?我一直在阅读有关urlencode,urlrawencode和包含的内容,这些内容在php文档站点中以注释的形式出现:

Hi im using the next function to create a tree directory menu in my website, the directories include a lot of pdf and excel, sometimes the name of this files have accents, spaces and ñ, My application work perfectly in OSX (mac) but a soon I uploaded in my godaddy server (linux), all the characters with accent were replace by the ? character breaking all the names and the link. Do you know how to deal with this issue? I been reading about urlencode, urlrawencode, inclusive I read, this comment in the php documentation site as comment:

Scandir无法与非英语字符(例如法语)一起正常使用 文件名中的重音符号,例如éàçè...).由于PHP不 在PHP 6之前支持unicode操作,这不是bug.

Scandir does not work properly with non-english caracters (like french accents for example : éàçè...) in the files name. As PHP does not support unicode operations until PHP 6, this is not a bug.

我希望有人能帮助我解决这个问题.

I hope somebody can help me in solve this.

function listFolderFiles($dir){
    $ffs = scandir($dir);
    echo '<ul class="transparencia">';
    foreach($ffs as $ff){
        if($ff != '.' && $ff != '..' && $ff != '.DS_Store'){
            $stringFileDir = $dir.'/'.$ff;
            echo '<li>';
            if(is_file($stringFileDir)){
                echo "<a href='transparencia/".$dir.'/'.$ff."' data-type='".pathinfo($stringFileDir)['extension']."' target='_blank'>".$ff."</a>";
            }else{
                echo "<span class='more'>+</span>".urldecode($ff);
            }


                if(is_dir($dir.'/'.$ff)){
                    listFolderFiles($dir.'/'.$ff);
                }

            echo '</li>';
        }
    }
    echo '</ul>';
}

推荐答案

简单的答案是linux不接受重音符号,因此如果您想在其上添加重音符号,则现在无法在linux服务器中使用scandir,这就是为什么在OSX中可以工作并且在Windows中也是如此.我在最后更改了脚本.

The answer simple is linux dont accept accents, so is impossible to use scandir in linux server right now if you want accents on it, thats why in OSX work and also in Windows. I changed my script at the end.

这篇关于Linux中带有重音符号的scandir问题在OSX中可以正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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