Skip to content

Instantly share code, notes, and snippets.

@picasso250
Created December 19, 2017 04:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save picasso250/11caf6eb47b28b4e3b990223c767e944 to your computer and use it in GitHub Desktop.
Save picasso250/11caf6eb47b28b4e3b990223c767e944 to your computer and use it in GitHub Desktop.
unzip a zip file on windows, preserve the right encode chinese
<?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