Exemplo n.º 1
0
 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;
     }
 }
Exemplo n.º 2
0
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
	<head>
		<script src="js/jquery.js"></script>
		<script src="js/jquery.progressbar.min.js"></script>
	</head>
	<body>
<?php 
ini_set('error_reporting', E_ALL);
ini_set('display_errors', 1);
include 'CurlAxel.php';
//$fileurl = "http://cachefly.cachefly.net/100mb.test";
$fileurl = "http://93.190.137.8/1000mb.bin";
echo "downloading {$fileurl} <br>";
$curlaxel = new CurlAxel();
$curlaxel->setUrl($fileurl);
$curlaxel->setProgressCallback(true);
$curlaxel->setBufferSize(32 * 1024 * 1024);
$curlaxel->activeLog(true);
$curlaxel->download();
Exemplo n.º 3
0
 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);
 }