Skip to content

Instantly share code, notes, and snippets.

@harryxu
Created November 14, 2018 10:42
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 harryxu/ef4ad97bb2f2fb61797393ac59e3cc12 to your computer and use it in GitHub Desktop.
Save harryxu/ef4ad97bb2f2fb61797393ac59e3cc12 to your computer and use it in GitHub Desktop.
解压vendor.zip
<?php
function extractVendor($rootPath)
{
$vendorArchive = "$rootPath/vendor.zip";
$vendorDir = "$rootPath/vendor";
if (!file_exists($vendorArchive)) {
return "$vendorArchive 文件不存在";
}
if (file_exists($vendorDir) && $_REQUEST['vforce'] !== 'fuzip') {
return 'vendor 目录已存在,若需要强制解压覆盖,请加入强制参数';
}
$zip = new ZipArchive();
$res = $zip->open($vendorArchive);
if ($res === true) {
$tmpDir = "$rootPath/vendor" . uniqid();
$zip->extractTo($tmpDir);
$zip->close();
if (file_exists($vendorDir)) {
rmdir($vendorDir);
}
rename("$tmpDir/vendor", $vendorDir);
rmdir($tmpDir);
echo '解压完成';
} else {
echo '读取文件失败';
}
}
echo extractVendor(__DIR__);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment