What encoding does ZipArchive use to store file na

2019-06-19 18:29发布

I'm using the php ZipArchive class in order to generate a zip archive. I use the second parameter of the addFile method in order to set the name of the file in the archive (since the real file on disk has a different name). Some of the names must contain french accents (such as é). When I download the archive, the accents aren't correctly displayed in the file name. What encoding should I use for the file names ? (the application uses UTF-8)

3条回答
Explosion°爆炸
2楼-- · 2019-06-19 18:52

Zip files don't have a specified encoding; the archive tool must guess (or assume) the encoding used. Try CP1252 first, then go from there.

查看更多
做个烂人
3楼-- · 2019-06-19 19:04

It is php bug #53948, see official bug report.

Suggested workaround (worked for me):

$zip->addFile($file, iconv("UTF-8", "CP852", $local_name));
查看更多
Emotional °昔
4楼-- · 2019-06-19 19:09

Use DOS encoding. My file names has cyrillic characters, so I'm encoding the file names from cp1251 (Windows) to cp866 (DOS), upon passing the filename to $zip->addFile().

查看更多
登录 后发表回答