/**
  * Create a temporary directory
  *
  * @param $dir  string based dir to create temporary directory
  * @param $prefix  string prefix for temporary directory name
  * @param $mod  int unix permission formated number
  *
  * @return  string path to directory
  */
 function tmpDir($dir = null, $prefix = null, $mod = 0700)
 {
     $dir = empty($dir) ? ja_sys_get_temp_dir() : $dir;
     $tmpName = jaTempnam($dir, $prefix);
     if (JFile::exists($tmpName)) {
         JFile::delete($tmpName);
     }
     if (!JFolder::exists($tmpName)) {
         JFolder::create($tmpName, $mod);
     }
     return FileSystemHelper::clean($tmpName . DS);
 }
 /**
  *
  * @param $url
  * @param $savePath
  * @param $options
  *
  * @return {array("savePath"=>$savePath, "error"=>curl_error(), "info"=>curl_getinfo())}
  */
 public static function downloadFile($savePath, $url, $data, $options = null)
 {
     if (substr($savePath, -1) == '/' || JFolder::exists($savePath)) {
         $targetDir = $savePath;
         $savePath = jaTempnam(ja_sys_get_temp_dir(), 'c_');
     }
     /*if (($fh = fopen($savePath, "wb")) === false) {
     		jaucRaiseMessage("Can not open file: {$savePath}", true);
     		//throw new Exception("CURL ERROR:: Can not open file: $savePath");
     		return false;
     		}*/
     $result = NetworkHelper::doPOST($url, $data, $options);
     if (!empty($result["error"])) {
         return false;
     }
     $test = JFile::write($savePath, $result["content"]);
     if (!$test) {
         return false;
     }
     $result["savePath"] = $savePath;
     return $result;
 }
Beispiel #3
0
 function _downloadUpgradePackage($product, $upgradeVersion)
 {
     if ($this->isLocalMode($product)) {
         return $this->_downloadUpgradePackageLocal($product, $upgradeVersion);
     }
     $content["service"] = "downloadUpgradePackage";
     $content["args"]["product"] = $product->getFullInfo();
     $content["args"]["newVersion"] = $upgradeVersion;
     $message = "json=" . json_encode($this->buildMessage($content));
     $tmpFile = jaTempnam(ja_sys_get_temp_dir(), 'ja');
     $result = NetworkHelper::downloadFile($tmpFile, $this->getServiceUrl($product), $message);
     $downloadedFile = $result["savePath"];
     if (!JFile::exists($downloadedFile)) {
         //throw new Exception('[UpdaterClient] Fail to download upgrade package', 100);
         jaucRaiseMessage("Error occur when downloading upgrade package!", true);
         return false;
     } else {
         @chmod($downloadedFile, 0644);
         return $downloadedFile;
     }
 }