当前位置: 首页>>代码示例>>PHP>>正文


PHP FileUtil::uncompressFile方法代码示例

本文整理汇总了PHP中FileUtil::uncompressFile方法的典型用法代码示例。如果您正苦于以下问题:PHP FileUtil::uncompressFile方法的具体用法?PHP FileUtil::uncompressFile怎么用?PHP FileUtil::uncompressFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在FileUtil的用法示例。


在下文中一共展示了FileUtil::uncompressFile方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: validateUploadPackage

 /**
  * Validates the upload package input.
  */
 protected function validateUploadPackage()
 {
     if (empty($this->uploadPackage['tmp_name'])) {
         throw new UserInputException('uploadPackage', 'uploadFailed');
     }
     // try to unzip zipped package files
     if (preg_match('!\\.(tar\\.gz|tgz)$!', basename($this->uploadPackage['name']))) {
         $tmpFilename = FileUtil::getTemporaryFilename('package_', '.tar');
         if (FileUtil::uncompressFile($this->uploadPackage['tmp_name'], $tmpFilename)) {
             @unlink($this->uploadPackage['tmp_name']);
             $this->uploadPackage['tmp_name'] = $tmpFilename;
         }
     } else {
         $tmpFilename = FileUtil::getTemporaryFilename('package_', '.tar');
         if (@copy($this->uploadPackage['tmp_name'], $tmpFilename)) {
             @unlink($this->uploadPackage['tmp_name']);
             $this->uploadPackage['tmp_name'] = $tmpFilename;
         }
     }
     $this->archive = new PackageArchive($this->uploadPackage['tmp_name'], $this->package);
     $this->validateArchive('uploadPackage');
 }
开发者ID:joaocustodio,项目名称:EmuDevstore-1,代码行数:25,代码来源:PackageStartInstallForm.class.php

示例2: downloadPackage

 /**
  * Tries to download a package from available update servers.
  * 
  * @param	string		$package		package identifier
  * @param	array		$packageUpdateVersions	package update versions
  * @return	string		tmp filename of a downloaded package
  */
 protected function downloadPackage($package, $packageUpdateVersions)
 {
     // get download from cache
     if ($filename = $this->getCachedDownload($package, $packageUpdateVersions[0]['package'])) {
         return $filename;
     }
     // download file
     $authorizationRequiredException = array();
     $systemExceptions = array();
     foreach ($packageUpdateVersions as $packageUpdateVersion) {
         try {
             // get auth data
             $authData = self::getAuthData($packageUpdateVersion);
             // send request
             if (!empty($packageUpdateVersion['file'])) {
                 $response = self::sendRequest($packageUpdateVersion['file'], array(), $authData);
             } else {
                 $response = self::sendRequest($packageUpdateVersion['server'], array('packageName' => $packageUpdateVersion['package'], 'packageVersion' => $packageUpdateVersion['packageVersion']), $authData);
             }
             // check response
             // check http code
             if ($response['httpStatusCode'] == 401) {
                 throw new PackageUpdateAuthorizationRequiredException($packageUpdateVersion['packageUpdateServerID'], !empty($packageUpdateVersion['file']) ? $packageUpdateVersion['file'] : $packageUpdateVersion['server'], $response);
             }
             if ($response['httpStatusCode'] != 200) {
                 throw new SystemException(WCF::getLanguage()->get('wcf.acp.packageUpdate.error.downloadFailed', array('$package' => $package)) . ' (' . $response['httpStatusLine'] . ')', 18009);
             }
             // write content to tmp file
             $filename = FileUtil::getTemporaryFilename('package_');
             $file = new File($filename);
             $file->write($response['content']);
             $file->close();
             // test compression
             if (substr($response['content'], 0, 2) == "‹") {
                 $tmpFilename = FileUtil::getTemporaryFilename('package_', '.tar');
                 if (FileUtil::uncompressFile($filename, $tmpFilename)) {
                     @unlink($filename);
                     $filename = $tmpFilename;
                 }
             }
             unset($response['content']);
             // test package
             $archive = new PackageArchive($filename);
             $archive->openArchive();
             $archive->getTar()->close();
             // cache download in session
             $this->cacheDownload($package, $packageUpdateVersion['packageVersion'], $filename);
             return $filename;
         } catch (PackageUpdateAuthorizationRequiredException $e) {
             $authorizationRequiredException[] = $e;
         } catch (SystemException $e) {
             $systemExceptions[] = $e;
         }
     }
     if (count($authorizationRequiredException)) {
         throw array_shift($authorizationRequiredException);
     }
     if (count($systemExceptions)) {
         throw array_shift($systemExceptions);
     }
     return false;
 }
开发者ID:joaocustodio,项目名称:EmuDevstore-1,代码行数:69,代码来源:PackageUpdate.class.php

示例3: installPackages

 /**
  * Registers with wcf setup delivered packages in the package installation queue.
  */
 protected function installPackages()
 {
     // init database connection
     $this->initDB();
     // enable regular cache
     self::$cacheObj = new CacheHandler();
     // get admin account
     //$admin = User::getNewest();
     $admin = new UserSession(1);
     // get delivered packages
     $wcfPackageFile = '';
     $otherPackages = array();
     $tar = new Tar(SETUP_FILE);
     foreach ($tar->getContentList() as $file) {
         if ($file['type'] != 'folder' && StringUtil::indexOf($file['filename'], 'install/packages/') === 0) {
             $packageFile = basename($file['filename']);
             $packageName = preg_replace('!\\.(tar\\.gz|tgz|tar)$!', '', $packageFile);
             if ($packageName == 'com.woltlab.wcf') {
                 $wcfPackageFile = $packageFile;
             } else {
                 $isStrato = false;
                 //(!empty($_SERVER['DOCUMENT_ROOT']) && (strpos($_SERVER['DOCUMENT_ROOT'], 'strato') !== false));
                 if (!$isStrato && preg_match('!\\.(tar\\.gz|tgz)$!', $packageFile)) {
                     // try to unzip zipped package files
                     if (FileUtil::uncompressFile(TMP_DIR . TMP_FILE_PREFIX . $packageFile, TMP_DIR . TMP_FILE_PREFIX . $packageName . '.tar')) {
                         @unlink(TMP_DIR . TMP_FILE_PREFIX . $packageFile);
                         $packageFile = $packageName . '.tar';
                     }
                 }
                 $otherPackages[$packageName] = $packageFile;
             }
         }
     }
     $tar->close();
     // register packages in queue
     // get new process id
     $sql = "SELECT\tMAX(processNo) AS processNo\n\t\t\tFROM\twcf" . WCF_N . "_package_installation_queue";
     $result = self::getDB()->getFirstRow($sql);
     $processID = intval($result['processNo']) + 1;
     $insertSQL = '';
     // search existing wcf package
     $sql = "SELECT\tCOUNT(*) AS count\n\t\t\tFROM\twcf" . WCF_N . "_package\n\t\t\tWHERE\tpackage = 'com.woltlab.wcf'";
     $row = self::getDB()->getFirstRow($sql);
     if (!$row['count']) {
         if (empty($wcfPackageFile)) {
             throw new SystemException('the essential package com.woltlab.wcf is missing.', 11007);
         }
         // register virtual wcfsetup package for the calculation of the progress bar during the package installation
         $insertSQL = "(" . $processID . ", " . $admin->userID . ", 'com.woltlab.wcfsetup', '', 0, 1, 'setup')";
         // register essential wcf package
         $insertSQL .= ",(" . $processID . ", " . $admin->userID . ", 'com.woltlab.wcf', '" . escapeString(TMP_DIR . TMP_FILE_PREFIX . $wcfPackageFile) . "', 0, 0, 'setup')";
     }
     // register all other delivered packages
     asort($otherPackages);
     foreach ($otherPackages as $packageName => $packageFile) {
         if (!empty($insertSQL)) {
             $insertSQL .= ',';
         }
         $insertSQL .= "(" . $processID . ", " . $admin->userID . ", '" . escapeString($packageName) . "', '" . escapeString(TMP_DIR . TMP_FILE_PREFIX . $packageFile) . "', 1, 0, 'setup')";
     }
     if (!empty($insertSQL)) {
         $sql = "INSERT INTO\twcf" . WCF_N . "_package_installation_queue\n\t\t\t\t\t\t(processNo, userID, package, archive, cancelable, done, installationType)\n\t\t\t\tVALUES\t\t" . $insertSQL;
         self::getDB()->sendQuery($sql);
     }
     // login as admin
     $factory = new SessionFactory();
     $session = $factory->create();
     $session->changeUser($admin);
     $session->register('masterPassword', 1);
     $session->update();
     self::getDB()->sendShutdownUpdates();
     // TODO: print message if delete fails
     $installPhpDeleted = @unlink('./install.php');
     $testPhpDeleted = @unlink('./test.php');
     $wcfSetupTarDeleted = @unlink('./WCFSetup.tar.gz');
     // print page
     WCF::getTPL()->assign(array('installPhpDeleted' => $installPhpDeleted, 'wcfSetupTarDeleted' => $wcfSetupTarDeleted));
     WCF::getTPL()->display('stepInstallPackages');
     // delete tmp files
     if (($files = glob(TMP_DIR . TMP_FILE_PREFIX . '*')) !== false) {
         foreach ($files as $file) {
             if (!preg_match("%.*\\.tar(\\.gz)?\$%", $file)) {
                 @unlink($file);
             }
         }
     }
 }
开发者ID:joaocustodio,项目名称:EmuDevstore-1,代码行数:90,代码来源:WCFSetup.class.php

示例4: unzipPackageArchive

 /**
  * Unzips compressed package archives.
  * 
  * @param 	string		$archive	filename
  * @return 	string		new filename
  */
 public static function unzipPackageArchive($archive)
 {
     if (!FileUtil::isURL($archive)) {
         $tar = new Tar($archive);
         $tar->close();
         if ($tar->isZipped()) {
             $tmpName = FileUtil::getTemporaryFilename('package_');
             if (FileUtil::uncompressFile($archive, $tmpName)) {
                 return $tmpName;
             }
         }
     }
     return $archive;
 }
开发者ID:joaocustodio,项目名称:EmuDevstore-1,代码行数:20,代码来源:PackageArchive.class.php


注:本文中的FileUtil::uncompressFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。