dtng5978 2014-02-27 12:27
浏览 100
已采纳

获取UTF-8文件名以使用PHP ZipArchive

I have a file that I want to add to a Zip with PHP, which is encoded in UTF-8. Here is the filename: 'µ漢字ääÖÅ.txt'.

Now, to get this file even to save to the filesystem I had to do this:

$filename = "µ漢字ääÖÅ.txt";
$codepage = 'Windows-' . trim(strstr(setlocale(LC_CTYPE, 0), '.'), '.');
$encoded_filename = iconv('UTF-8', $codepage.'//IGNORE', $filename);
file_put_contents($encoded_filename, "text");

Now when I want to add the file to the ziparchive I use the following code:

$zip = new \ZipArchive();
$zip->open('test.zip', \ZIPARCHIVE::CREATE);
$zip->addFile($encoded_filename, $encoded_filename);
$zip->close();

Which results in a zip file containing the file name 'ÁõõÍ+.txt'. How do I get it to save correctly?

  • 写回答

1条回答 默认 最新

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥100 制作短链接和api接口的
      • ¥15 星河亮点sp9500测试指导
      • ¥15 dataframe 某列数据分列
      • ¥15 风扇导入fluent后仿真压力和速度数据卡在旋转域
      • ¥15 echarts中dataZoom报错
      • ¥15 求解答:《前端综合基础》作为一门课程的话,应该包含哪些内容?
      • ¥15 软件原型系统开发+实例测试
      • ¥50 C#上位机调试Win USB
      • ¥15 java基础望榜榜 java基础望榜榜
      • ¥15 comsol 周期性端口