【问题标题】:PHP: file_exists don't work when file name is in non-latin languagePHP:当文件名是非拉丁语言时,file_exists 不起作用
【发布时间】:2013-06-08 06:32:47
【问题描述】:

我有以下代码

    $file = WWW_ROOT."/upload/files/".$id.".plist";
/* $file=iconv('utf-8', 'latin1', $file); */
/*  print_r($file);exit; */
if (file_exists($file)) {
  //downloading
}

当 $id 有类似 جدة 之类的文件时,会出现问题,尽管它存在.. 我可以添加什么代码来将 $id 转换为 utf-8 并读取磁盘上的文件?

【问题讨论】:

    标签: php utf-8 file-exists


    【解决方案1】:

    不要删除iconv ...你需要这样的东西......

    $id = "file_å";
    $file = __DIR__ . "/" . $id . ".plist";
    $file = iconv('utf-8', 'cp1252', $file);
    
    /* print_r($file);exit; */
    if (file_exists($file)) {
        // downloading
        print("OK");
    }
    

    【讨论】:

    • 它给出了 iconv():检测到输入字符串中的非法字符 [APP/Controller/TestController.php,第 48 行]
    猜你喜欢
    • 2022-06-26
    • 2014-07-16
    • 2017-05-14
    • 2017-03-11
    • 2016-11-12
    • 2012-02-04
    • 2011-11-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多