<?php
set_time_limit(0);
$config
= (object)[
'zips' => __DIR__ . '/zips',
'uniapp' => __DIR__ . '/uniapp',
];
downloadAndExtract('https:
function
downloadAndExtract(
$zipUrl
,
$key
)
{
global
$config
;
echo
"正在下载: $zipUrl\n"
;
$zipData
=
file_get_contents
(
$zipUrl
);
$zipFile
=
$config
->zips .
"/$key-"
.
date
('Ymd-His') . '.zip';
file_put_contents
(
$zipFile
,
$zipData
);
echo
"正在解压到 {$config->$key} \n"
;
$zip
=
new
ZipArchive;
if
(
$key
=== 'uniapp') {
if
(
$zip
->open(
$zipFile
) === true) {
$folder
=
$zip
->getNameIndex(0);
for
(
$i
= 1;
$i
<
$zip
->numFiles;
$i
++) {
$filename
=
$zip
->getNameIndex(
$i
);
if
(
substr
(
$filename
, -1, 1) === '/') {
continue
;
}
$newFileName
=
$config
->
$key
. '/' .
str_replace
(
$folder
, '',
$filename
);
if
(!
file_exists
(dirname(
$newFileName
))) {
mkdir
(dirname(
$newFileName
), 0644, true);
}
copy
(
"zip://{$zipFile}#{$filename}"
,
$newFileName
);
}
$zip
->close();
}
}
echo
"-------------- SUCESS --------------\n"
;
}