|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2016-05-11 16:30 UTC] thomas dot kuhn dot berlin at gmail dot com
Description:
------------
New in PHP7 on Windows: When filenames contain non-us-ascii-letters like öäü or asian chars etc., ZipArchive creates filenames in a way that those files are not accessible via PHP because the encoding is wrong.
testscript output PHP 5.5.35:
php default_charset: UTF-8
bool(true)
testscript output PHP 7.0.6:
php default_charset: UTF-8
bool(false)
run on Windows Server 2012 R2 and Windows7
Test script:
---------------
print "php default_charset: ".ini_get('default_charset')."\n"; // just 4 info (UTF-8)
$filename = "bugtest_müller-lüdenscheid.zip"; // just an example
$filename = utf8_encode($filename); // simulating my database delivering utf8-string
$zip = new ZipArchive();
if( $zip->open($filename, ZipArchive::CREATE | ZipArchive::OVERWRITE) === true )
{
$zip->addFile('bugtest.php', 'bugtest.php'); // copy of script file itself
$zip->close();
}
var_dump( is_file($filename) ); // delivers ?
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 08 23:00:01 2025 UTC |
Using the following slightly modified script, I can't reproduce the issue with PHP 7.0.6 (VC14 x86 Non Thread Safe (2016-Apr-29 00:38:17)) on Windows 10: <?php $filename = "m\xc3\xbcller"; $zip = new ZipArchive; var_dump($zip->open($filename, ZipArchive::CREATE|ZipArchive::OVERWRITE)); var_dump($zip->addFromString('foo', 'bar')); var_dump($zip->close()); var_dump(file_exists($filename)); Output bool(true) bool(true) bool(true) bool(true) What results do you get running this script?Thanks for testing the script. But actually, I have to apologize, because I didn't carefully check my test results which were wrong as I did run the script with PHP 5.6 first, which created the zip file as expected, and later running with PHP 7.0.6 found the zip created by the earlier run. So, I can reproduce the issue with PHP 7.0.6 (both x86 and x64). While file_put_contents("m\xc3\xbcller", …) creates the file `müller` as expected, ZipArchive creates the file `müller`. Apparently, ZipArchive maps filenames from UTF-8 to UTF-16/UCS-2, while the plain file functions do not. That might be caused by recent builds of the bundled libzip using the *W*idechar instead of the *A*nsi variants of the WinAPI.