public function read() { $version = $this->getVersion($_GET["id"]); //检测是不是相邻版本 if (!$this->isAdjoiningVersion(DBC("system.version"), $version["version"])) { $this->error("you only can upgrade current version to the adjoining version."); return; } //文件路径为HTTP绝对地址 if (strStartWith($version["file"], "http://") or strStartWith($version["file"], "https://")) { $remoteUri = $version["file"]; } else { $remoteUri = file_get_contents($this->server . "getDownload/id/" . $version["id"]); } $localPathFull = $this->getLocalPath($version["file"]); $tmp = explode("/", $localPathFull); $localName = array_pop($tmp); $localPath = implode("/", $tmp); import("@.ORG.CurlAxel"); $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(true); $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) { $this->error("download_failed"); return; } }
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); }