Created
December 19, 2017 04:48
-
-
Save picasso250/11caf6eb47b28b4e3b990223c767e944 to your computer and use it in GitHub Desktop.
unzip a zip file on windows, preserve the right encode chinese
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 | |
$zip = new ZipArchive; | |
$res = $zip->open($file); | |
if ($res === TRUE) { | |
for ($i=0;($filename=$zip->getNameIndex ($i))!==false; $i++) { | |
echo "$filename\n"; | |
if ($filename[strlen($filename)-1] == '/') { | |
$filename = iconv('UTF-8', 'GBK', $filename); | |
if (!is_dir($filename)) { | |
mkdir($filename); | |
} | |
} else { | |
$filename = iconv('UTF-8', 'GBK', $filename); | |
file_put_contents($filename, $zip->getFromIndex($i)); | |
} | |
} | |
echo 'OK ',date("Y-m-d H:i:s"); | |
// $zip->extractTo('.'); | |
// $zip->close(); | |
} else { | |
echo 'failed, code:' . $res; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment