Skip to content

Instantly share code, notes, and snippets.

@GithubMrxia
Last active February 28, 2020 10:32
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 GithubMrxia/2b6e5a0382734434576f9f9d148faddb to your computer and use it in GitHub Desktop.
Save GithubMrxia/2b6e5a0382734434576f9f9d148faddb to your computer and use it in GitHub Desktop.
php解压zip文件并把所有图片放到制定目录下
<?php
$za = new ZipArchive();
$res = $za->open('test.zip');
if (!$res) {
return $this->respApiRequestFail('解压失败');
}
$path = storage_path('/path/to');
for ($i = 0; $i < $za->numFiles; $i++) {
$fileInfo = $za->statIndex($i);
$fileName = basename($fileInfo['name']);
$fileArr = explode('.', $fileName);
$fileExtension = end($fileArr);
if (!$fileExtension || !in_array($fileExtension, ['jpg', 'jpeg', 'png'])) {
continue;
}
$fileContent = $za->getStream($fileInfo['name']);
file_put_contents($path . '/' . $fileName, $fileContent);
}
$za->close();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment