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: 2015-05-19 09:27 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: None
 [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)

Pull Requests

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.
 [2015-05-19 07:22 UTC] allan dot mascarenhas1987 at gmail dot com
Can we have fix this issue ? 

PHP Version => 5.3.10-1ubuntu3.17
Extension Version => $Id: php_zip.c 321634 2012-01-01 13:15:04Z felipe $
Zip version => 1.9.1
Libzip version => 0.9.0
Web server => niginx

My problem is i can't update PHP to latest version, due code dependency. 

can someone look into this ?
 [2015-05-19 09:27 UTC] requinix@php.net
@allan: PHP 5.3 reached end-of-life last August. http://php.net/eol.php
 [2015-05-19 11:44 UTC] allan dot mascarenhas1987 at gmail dot com
Is it fixed in higher versions of PHP ?

Also is there any technical work around to fix this issue ?

We are currently using Drupal 6 CMS, we have around 500+ custom modules and we can't afford heavy testing for this change.
 [2015-11-25 12:51 UTC] 1710ef4e at opayq dot com
2016 is coming soon...
 [2016-12-27 07:55 UTC] 498936940 at qq dot com
Can we have fix this issue ? 

PHP Version => PHP Version 5.6.21-1+donate.sury.org~precise+4
Zip version => 1.12.5 
Libzip version => 0.11.2 
Web server => niginx

My problem is i can't update PHP to latest version, due code dependency. 

can someone look into this ?

2017 is coming soon...
 [2017-01-06 02:19 UTC] 498936940 at qq dot com
<?php
//解决Windows系统自带压缩软件zipped在PHP中解压缩乱码问题
//依赖Linux的zip+unzip命令
//https://bugs.php.net/bug.php?id=53948

putenv('LC_ALL=zh_CN.UTF-8');
$filePath = '/home/anyuan/workspace';
$fileName = 'test.zip';
exec(
    'cd '.$filePath.' &&
    unzip -O GBK -o -d ./'.$fileName.'_extract '.$fileName.' &&
    rm -rf ./'.$fileName.' &&
    cd ./'.$fileName.'_extract &&
    zip -r -A ../'.$fileName.' ./* &&
    cd ../ &&
    rm -rf ./'.$fileName.'_extract'
);
?>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 18:01:29 2024 UTC