Bug #71034 [Nab]: Can't add UTF-8 filenames as UTF-8 to ZIP archive

From: Date: Sun, 06 Dec 2015 16:52:20 +0000
Subject: Bug #71034 [Nab]: Can't add UTF-8 filenames as UTF-8 to ZIP archive
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-197638@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=71034&edit=1 ID: 71034 Updated by: ab@php.net Reported by: slavikca at gmail dot com Summary: Can't add UTF-8 filenames as UTF-8 to ZIP archive Status: Not a bug Type: Bug Package: Zip Related Operating System: Ubuntu 14.04 PHP Version: 5.6.16 Block user comment: N Private report: N New Comment: Hmm ... or do I err, and the zip utility is actually converts to pure Unicode? Than could explain the difference in the output showing, still confusing. Anyway, adding filenames in UTF-8 works and is not an issue. Thanks. Previous Comments: ------------------------------------------------------------------------ [2015-12-06 16:37:29] ab@php.net Thanks for the additional info. It seems that it is not a bug in PHP. In 7.0.0, i use $zip->addFile(__FILE__, "\u{442}\u{435}\u{441}\u{442}123.txt"); which effectively adds a file named тест123.txt to the zip archive. This is what I see in my terminal $ unzip -l -U bug71034.zip Archive: bug71034.zip Length Date Time Name --------- ---------- ----- ---- 319 2015-12-06 17:25 тест123.txt --------- ------- 319 1 file Same i get with your original piece of code. Please note, in the description you list to see the following: /var/www/test/web/#U0442#U0435#U0441#U0442123 That means terminal is not in UTF-8. It is not critical for the PHP behavior, but it avoids any possible misinterpretation when you list out the results. So were worth it to configure. so after all, the issue on your side appears to be that the filename you pass to ext/zip is not UTF-8. Consequently that name is stored into the zip file. It is weird given all your locale is UTF-8 and the PHP file with the hard coded file name as well, but it is the only explanation for the behavior. The filename can be forced to UTF-8 when you fe convert it with iconv and pass it as second argument to ZipArchive::addFile(). Thanks. ------------------------------------------------------------------------ [2015-12-05 06:48:20] slavikca at gmail dot com Also, today tried to test with this system: - PHP 7.0.0 - Ubuntu 14.04 - Zip version 1.13.0 - Libzip version 1.0.1 Same results. Archive created with filenames stored not in UTF-8. Here is phpinfo page (may be removed later): http://dev.slavikf.com/info.php ------------------------------------------------------------------------ [2015-12-05 02:24:58] slavikca at gmail dot com 1) is the current locale UTF-8 2) is the terminal charset UTF-8 Yes, all my locales are UTF-8: $ locale LANG=en_US.UTF-8 LC_CTYPE="en_US.UTF-8" LC_NUMERIC="en_US.UTF-8" LC_TIME="en_US.UTF-8" LC_COLLATE="en_US.UTF-8" LC_MONETARY="en_US.UTF-8" LC_MESSAGES="en_US.UTF-8" LC_PAPER="en_US.UTF-8" LC_NAME="en_US.UTF-8" LC_ADDRESS="en_US.UTF-8" LC_TELEPHONE="en_US.UTF-8" LC_MEASUREMENT="en_US.UTF-8" LC_IDENTIFICATION="en_US.UTF-8" 3) is the actual filename string used in PHP UTF-8, especially the filename is hardcoded - your script is UTF-8 encoded file If your question about file, where I have PHP code, then - yes: $ file index.php index.php: PHP script, UTF-8 Unicode text If you are saying, that I need to force PHP to use string in UTF-8 - I do not know, how to do it. Do I have to use some commands / flags? ------------------------------------------------------------------------ [2015-12-05 02:07:15] ab@php.net Please check the following: - is the current locale UTF-8 - is the terminal charset UTF-8 - is the actual filename string used in PHP UTF-8, especially the filename is hardcoded - your script is UTF-8 encoded file Only if all of these match, it could be a bug in PHP on in libzip. Thanks. ------------------------------------------------------------------------ [2015-12-04 21:45:39] slavikca at gmail dot com In case, if it was not clear from my original issue description: output of "unzip" from linux shows UTF-8 characters. So, that is example of adding filename correctly, in UTF-8. output of "unzip" from file, create in PHP shows filename seemingly correctly (same as original), but it is not in UTF-8. That's bad, because it will show correct filename only in the systems with same locale settings. If it is different - it will be garbled. But UTF-8 will work correctly 100% on any system (which supports UTF-8) with any locale. ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at https://bugs.php.net/bug.php?id=71034 -- Edit this bug report at https://bugs.php.net/bug.php?id=71034&edit=1

« previous php.bugs (#197638) next »