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)
Asked
Active
Viewed 6,843 times
6
-
Zip's a pretty old format, and predates Unicode. Older pre-2007 versions of the format most likely just use standard extended ascii. After '07, the new spec allowed for UTF-8. Check which file version you're generating. – Marc B Feb 15 '11 at 16:20
4 Answers
9
It is php bug #53948, see official bug report.
Suggested workaround (worked for me):
$zip->addFile($file, iconv("UTF-8", "CP852", $local_name));

janedbal
- 91
- 1
- 5
4
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()
.

Marko
- 20,385
- 13
- 48
- 64

Aleksey Kuznetsov
- 623
- 6
- 10
-
-
I didn't figured it out, because I always knew it. :)) lol Well, actually I used RAR since 1992 or 1993. RAR was originally written for DOS and later ported to Windows as WinRAR. So DOS code tables is native for RAR. – Aleksey Kuznetsov Dec 01 '18 at 23:56
2
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.

Ignacio Vazquez-Abrams
- 776,304
- 153
- 1,341
- 1,358
-
1
-
What does the byte sequence of a filename look like, and what is it supposed to be in text? – Ignacio Vazquez-Abrams Feb 15 '11 at 15:31
1
Depends on the Windows system e.g French, internal zip of Windows use IBM850
as encoding.

Thanh Trung
- 3,566
- 3
- 31
- 42