Created
November 14, 2018 10:42
-
-
Save harryxu/ef4ad97bb2f2fb61797393ac59e3cc12 to your computer and use it in GitHub Desktop.
解压vendor.zip
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 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