Created
March 17, 2014 17:33
-
-
Save real34/9604201 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function fixFilenameEncoding($filename) { | |
return mb_convert_encoding($filename, 'ISO-8859-2', 'UTF-8'); | |
} | |
$zip = new ZipArchive; | |
$res = $zip->open('./elephant.zip', ZipArchive::CREATE); | |
if ($res === true) { | |
$filename = 'éléphant-man2.txt'; | |
$zip->addFromString(fixFilenameEncoding($filename), 'file content goes here'); | |
$zip->close(); | |
echo '<a href="elephant.zip">ok</a>'; | |
} else { | |
echo 'failed'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The probleme with this code, is that when opening / extracting the archive with a Zip client the "éléphant-man2.txt" file has an incorrectly encoded name "éléphant-man.txt".
Without the
fixFilenameEncoding()
the archive content is broken on Ubuntu/OSX and Windows.With the
fixFilenameEncoding()
call, it works on Ubuntu but not on the other OSes.Any idea about how to fix this?