function recursionCopy($src, $dst) { // 原目录,复制到的目录 $dst = realpath($dst); $src = realpath($src); $dir = opendir($src); $ignore = array(".", "..", ".DS_Store", "__MACOSX"); while (false !== ($file = readdir($dir))) { if (!in_array($file, $ignore)) { if (is_dir($src . '/' . $file)) { if (!is_dir($dst . '/' . $file)) { mkdir($dst . '/' . $file, 0777); } recursionCopy($src . '/' . $file, $dst . '/' . $file); } else { $rs = copy($src . '/' . $file, $dst . '/' . $file); } } } closedir($dir); }
public function insert() { //下载升级包 if ($_POST["doDownload"] && $_POST["version"]) { } //执行升级,需要zip模块支持 if ($_POST["doUpdate"] && $_POST["version"]) { $version = $this->getVersion($_POST["version"]); $zip = new ZipArchive(); $tmpFolder = $this->local . "update_" . $_POST["version"]; $rs = $zip->open($this->getLocalPath($version["file"])); if ($rs === true) { if (!is_dir($tmpFolder)) { $rs = mkdir($tmpFolder, 0777); } $zip->extractTo($tmpFolder); } $zip->close(); unlink($this->getLocalPath($version["file"])); //暂定根目录为ENTRY_PATH上级目录 //更新数据库 $sqlFile = $tmpFolder . "/upgrade.sql"; if (file_exists_case($sqlFile)) { $rs = importSQL($sqlFile); unlink($sqlFile); if (true !== $rs) { $this->error($rs[0]); return; } } //复制文件 recursionCopy($tmpFolder, dirname(ENTRY_PATH)); //删除更新文件 delDirAndFile($tmpFolder); //更新系统版本 $model = D("Config"); $model->where(array("alias" => 'system.version'))->save(array("value" => $version["version"])); } }
private function downloadAndZipAndCopy($remoteUri, $target) { $localName = md5(CTS) . ".zip"; $localPath = ENTRY_PATH . "/Data/apps/"; @mkdirs($localPath, 0777); import("@.ORG.CurlAxel"); if (!is_writeable($localPath)) { return $this->error("Temp dir is not writeable"); } $axel = new CurlAxel(); $axel->setUrl($remoteUri); $size = $axel->getFileSize($remoteUri); $axel->setProgressCallback(false); $axel->setTempDir(ENTRY_PATH . "Runtime/Temp"); $axel->setDownloadDir($localPath); $axel->setFilename($localName); $axel->setBufferSize(32 * 1024); $axel->activeLog(false); $axel->download(); $maxTry = 30; $sleep = 1; $try = 0; $downloaded = false; do { $try++; sleep($sleep); clearstatcache(); //下载成功 if (is_file($localPath . $localName) and filesize($localPath . $localName) == $size) { $downloaded = true; break; } } while ($try <= $maxTry); if (!$downloaded) { Log::write("Install app failed while download: " . $remoteUri . " to: " . $localPath); $this->error("install failed while download"); exit; } $zip = new ZipArchive(); $tmpFolder = ENTRY_PATH . "/Data/apps/installTmp"; $rs = $zip->open($localPath . $localName); if ($rs === true) { if (!is_dir($tmpFolder)) { mkdir($tmpFolder, 0777); } $zip->extractTo($tmpFolder); } $zip->close(); recursionCopy($tmpFolder, $target); return array($localPath . $localName, $tmpFolder); }