php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53948 ZIP archive UTF-8 filenames problem
Submitted: 2011-02-07 14:06 UTC Modified: 2013-12-16 13:58 UTC
From: asaf at lingnu dot com Assigned:
Status: Duplicate Package: Zip Related
PHP Version: 5.3.5 OS: linux
Private report: No CVE-ID:
 [2011-02-07 14:06 UTC] asaf at lingnu dot com
Description:
------------
when creating zip archive with non-english filenames, 
the filenames are not encoded correctly, upon extraction
you get them like ???_???.txt.
(tested with various unzipping software on windows/linux)

a suggested workaround, e.g:

$zip->addFile($file_data['path'], iconv("UTF-8","CP852",$file_name));

doesn't help

Test script:
---------------
<?php

   $zip = new ZipArchive();

   if ($zip->open('/tmp/test.zip', ZIPARCHIVE::CREATE) === TRUE) {

      $zip->addFile('/tmp/file.txt', 'קובץ.txt');

      $zip->close();

      echo "done";

   } else {

      echo "failed";

   }

?>


Expected result:
----------------
create a zip file which can be extracted reproducing the original file names.

Actual result:
--------------
non english file names comes out corrupted, e.g: ???_???.txt

Patches

php-5.3.3-ZIP-UTF8.patch (last revision 2012-02-19 15:47 UTC) by asaf at hadasa-oss dot net)

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-02-18 14:02 UTC] pajoye@php.net
-Status: Open +Status: Duplicate
 [2011-02-18 14:02 UTC] pajoye@php.net
#51929
 [2011-05-30 08:49 UTC] mikhail dot v dot gavrilov at gmail dot com
I also confirm this problem.

Workaround: Helps converting to your DOS encoding.
 [2011-06-10 23:27 UTC] killerloin at yahoo dot com
is this problem solved yet? I really need a solution.
 [2011-09-23 11:14 UTC] robert at softcom dot no
I also have a problem with this, so bump!
 [2011-12-01 13:49 UTC] nadavkav at gmail dot com
I experience the same issue.
While zipping Hebrew filenames on a CentOS 5.6 (GNU/LINUX) system
with php 5.2.x and 5.3.x
And then, trying to open the Zip file on a Windows XP system
In Which i get ?????.txt as filenames.

Please see more info on the Moodle developer TRACKER system:
http://tracker.moodle.org/browse/MDL-24928
 [2013-04-24 17:18 UTC] animelp at yahoo dot com dot ar
same issue with PHP 5.2.14
 [2013-04-24 18:43 UTC] pajoye@php.net
Use latest pecl release to have UTF-8 support.
 [2013-11-11 08:02 UTC] domnulnopcea at gmail dot com
Even if I use the latest pecl release (beta) the bug is still present!!!
 [2013-12-16 00:14 UTC] danhab2000 at yahoo dot com
Any solutions yet?
מה זה?!
 [2013-12-16 13:30 UTC] danhab2000 at yahoo dot com
Found solution.

http://stackoverflow.com/questions/20600843/php-ziparchive-non-english-filenames-return-funky-filenames-within-archive

To repeat in short, the below suggested workaround would work, except its wrong.  It should be CP862 not CP852.  (for hebrew)  See link.
 [2013-12-16 13:58 UTC] pajoye@php.net
or update to a more recent php version, 5.4+ or use latest zip from pecl.
 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Fri Apr 18 02:02:27 2014 UTC