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


PHP ZipArchive::extractTo方法代码示例

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


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

示例1: unzip_file

function unzip_file($zip_archive, $archive_file, $zip_dir)
{
    if (!is_dir($zip_dir)) {
        if (!defined('SUGAR_PHPUNIT_RUNNER')) {
            die("Specified directory '{$zip_dir}' for zip file '{$zip_archive}' extraction does not exist.");
        }
        return false;
    }
    $zip = new ZipArchive();
    $res = $zip->open($zip_archive);
    if ($res !== true) {
        if (!defined('SUGAR_PHPUNIT_RUNNER')) {
            die(sprintf("ZIP Error(%d): %s", $res, $zip->status));
        }
        return false;
    }
    if ($archive_file !== null) {
        $res = $zip->extractTo($zip_dir, $archive_file);
    } else {
        $res = $zip->extractTo($zip_dir);
    }
    if ($res !== true) {
        if (!defined('SUGAR_PHPUNIT_RUNNER')) {
            die(sprintf("ZIP Error(%d): %s", $res, $zip->status));
        }
        return false;
    }
    return true;
}
开发者ID:razorinc,项目名称:sugarcrm-example,代码行数:29,代码来源:php_zip_utils.php

示例2: unzip_content

function unzip_content()
{
    $zip = new ZipArchive();
    if (file_exists('application.zip')) {
        $res = $zip->open('application.zip');
        if ($res === TRUE) {
            echo '<p>Unzipped Application <i class="fa fa-check-circle-o"></i></p>';
            $zip->extractTo('./');
            $zip->close();
            unlink('application.zip');
        } else {
            echo '<p>Could not unzip application.zip <i class="fa fa-times-circle-o"></i></p>';
        }
    } else {
        echo '<p>Application already unzipped <i class="fa fa-check-circle-o"></i></p>';
    }
    new_line();
    if (file_exists('content.zip')) {
        $res = $zip->open('content.zip');
        if ($res === TRUE) {
            echo '<p>Unzipped Content <i class="fa fa-check-circle-o"></i></p>';
            $zip->extractTo('./');
            $zip->close();
            unlink('content.zip');
        } else {
            echo '<p>Could not unzip content.zip <i class="fa fa-times-circle-o"></i></p>';
        }
    } else {
        echo '<p>Content already unzipped <i class="fa fa-check-circle-o"></i></p>';
    }
    new_line();
}
开发者ID:nvq247,项目名称:Kxexnxh,代码行数:32,代码来源:install.php

示例3: extractTo

 /**
  * @param $destination
  * @throws IfwPsn_Wp_Module_Exception
  * @return bool
  */
 public function extractTo($destination)
 {
     if (!$this->_zip->extractTo($destination)) {
         throw new IfwPsn_Wp_Module_Exception('Could not extract archive.');
     }
     return true;
 }
开发者ID:jasmun,项目名称:Noco100,代码行数:12,代码来源:Archive.php

示例4: testZipArchive

 /**
  * Test all methods
  *
  * @param string $zipClass
  * @covers ::<public>
  */
 public function testZipArchive($zipClass = 'ZipArchive')
 {
     // Preparation
     $existingFile = __DIR__ . '/../_files/documents/sheet.xls';
     $zipFile = __DIR__ . '/../_files/documents/ziptest.zip';
     $destination1 = __DIR__ . '/../_files/documents/extract1';
     $destination2 = __DIR__ . '/../_files/documents/extract2';
     @mkdir($destination1);
     @mkdir($destination2);
     Settings::setZipClass($zipClass);
     $object = new ZipArchive();
     $object->open($zipFile, ZipArchive::CREATE);
     $object->addFile($existingFile, 'xls/new.xls');
     $object->addFromString('content/string.txt', 'Test');
     $object->close();
     $object->open($zipFile);
     // Run tests
     $this->assertEquals(0, $object->locateName('xls/new.xls'));
     $this->assertFalse($object->locateName('blablabla'));
     $this->assertEquals('Test', $object->getFromName('content/string.txt'));
     $this->assertEquals('Test', $object->getFromName('/content/string.txt'));
     $this->assertFalse($object->getNameIndex(-1));
     $this->assertEquals('content/string.txt', $object->getNameIndex(1));
     $this->assertFalse($object->extractTo('blablabla'));
     $this->assertTrue($object->extractTo($destination1));
     $this->assertTrue($object->extractTo($destination2, 'xls/new.xls'));
     $this->assertFalse($object->extractTo($destination2, 'blablabla'));
     // Cleanup
     $this->deleteDir($destination1);
     $this->deleteDir($destination2);
     @unlink($zipFile);
 }
开发者ID:HaiLeader,项目名称:quizz,代码行数:38,代码来源:ZipArchiveTest.php

示例5: upload

 /**
  * Upload component
  *
  * @requires component package file,
  *
  * @return bool;
  */
 public function upload()
 {
     $archive = new ZipArchive();
     $data_dir = ossn_get_userdata('tmp/components');
     if (!is_dir($data_dir)) {
         mkdir($data_dir, 0755, true);
     }
     $zip = $_FILES['com_file'];
     $newfile = "{$data_dir}/{$zip['name']}";
     if (move_uploaded_file($zip['tmp_name'], $newfile)) {
         if ($archive->open($newfile) === TRUE) {
             $archive->extractTo($data_dir);
             //make community components works on installer #394
             $validate = $archive->statIndex(0);
             $validate = str_replace('/', '', $validate['name']);
             $archive->close();
             if (is_dir("{$data_dir}/{$validate}") && is_file("{$data_dir}/{$validate}/ossn_com.php") && is_file("{$data_dir}/{$validate}/ossn_com.xml")) {
                 $archive->open($newfile);
                 $archive->extractTo(ossn_route()->com);
                 $archive->close();
                 $this->newCom($validate);
                 OssnFile::DeleteDir($data_dir);
                 return true;
             }
         }
     }
     return false;
 }
开发者ID:aidovoga,项目名称:opensource-socialnetwork,代码行数:35,代码来源:OssnComponents.php

示例6: extract

 /**
  * @param string $to - path where the archive should be extracted to
  * @return bool
  */
 public function extract($to)
 {
     $r = false;
     $ext = SPFs::getExt($this->_filename);
     switch ($ext) {
         case 'zip':
             $zip = new ZipArchive();
             if ($zip->open($this->_filename) === true) {
                 SPException::catchErrors(SPC::WARNING);
                 try {
                     $zip->extractTo($to);
                     $zip->close();
                     $r = true;
                 } catch (SPException $x) {
                     $t = Sobi::FixPath(Sobi::Cfg('fs.temp') . DS . md5(microtime()));
                     SPFs::mkdir($t, 0777);
                     $dir = SPFactory::Instance('base.fs.directory', $t);
                     if ($zip->extractTo($t)) {
                         $zip->close();
                         $dir->moveFiles($to);
                         $r = true;
                     }
                     SPFs::delete($dir->getPathname());
                 }
                 SPException::catchErrors(0);
             }
             break;
     }
     return $r;
 }
开发者ID:kishoreweblabs,项目名称:SobiPro,代码行数:34,代码来源:archive.php

示例7: extractArchive

 private function extractArchive()
 {
     $this->archive->close();
     $this->archive->open($this->archive_path);
     $this->archive->extractTo($this->extraction_path);
     $this->archive->close();
 }
开发者ID:pombredanne,项目名称:tuleap,代码行数:7,代码来源:ArtifactAttachmentExporterTest.php

示例8: extract

 /**
  * Extract files from archive to target directory
  *
  * @param string  $pathExtracted  Absolute path of target directory
  * @return mixed  Array of filenames if successful; or 0 if an error occurred
  */
 public function extract($pathExtracted)
 {
     if (substr_compare($pathExtracted, '/', -1)) {
         $pathExtracted .= '/';
     }
     $fileselector = array();
     $list = array();
     $count = $this->ziparchive->numFiles;
     if ($count === 0) {
         return 0;
     }
     for ($i = 0; $i < $count; $i++) {
         $entry = $this->ziparchive->statIndex($i);
         $filename = str_replace('\\', '/', $entry['name']);
         $parts = explode('/', $filename);
         if (!strncmp($filename, '/', 1) || array_search('..', $parts) !== false || strpos($filename, ':') !== false) {
             return 0;
         }
         $fileselector[] = $entry['name'];
         $list[] = array('filename' => $pathExtracted . $entry['name'], 'stored_filename' => $entry['name'], 'size' => $entry['size'], 'compressed_size' => $entry['comp_size'], 'mtime' => $entry['mtime'], 'index' => $i, 'crc' => $entry['crc']);
     }
     $res = $this->ziparchive->extractTo($pathExtracted, $fileselector);
     if ($res === false) {
         return 0;
     }
     return $list;
 }
开发者ID:nnnnathann,项目名称:piwik,代码行数:33,代码来源:ZipArchive.php

示例9: upload

 /**
  * Upload component
  *
  * @requires component package file,
  *
  * @return bool;
  */
 public function upload()
 {
     $archive = new ZipArchive();
     $data_dir = ossn_get_userdata('tmp/components');
     if (!is_dir($data_dir)) {
         mkdir($data_dir, 0755, true);
     }
     $zip = $_FILES['com_file'];
     $newfile = "{$data_dir}/{$zip['name']}";
     if (move_uploaded_file($zip['tmp_name'], $newfile)) {
         if ($archive->open($newfile) === TRUE) {
             $archive->extractTo($data_dir);
             $archive->close();
             $validate = pathinfo($zip['name'], PATHINFO_FILENAME);
             if (is_file("{$data_dir}/{$validate}/ossn_com.php") && is_file("{$data_dir}/{$validate}/ossn_com.xml")) {
                 $archive->open($newfile);
                 $archive->extractTo(ossn_route()->com);
                 $archive->close();
                 $this->newCom($validate);
                 OssnFile::DeleteDir($data_dir);
                 return true;
             }
         }
     }
     return false;
 }
开发者ID:alibasli,项目名称:Social-Network-PHP-Joomla,代码行数:33,代码来源:OssnComponents.php

示例10: unzip_file

function unzip_file($zip_archive, $archive_file, $zip_dir)
{
    if (!is_dir($zip_dir)) {
        if (defined('SUGAR_PHPUNIT_RUNNER') || defined('SUGARCRM_INSTALL')) {
            $GLOBALS['log']->fatal("Specified directory '{$zip_dir}' for zip file '{$zip_archive}' extraction does not exist.");
            return false;
        } else {
            die("Specified directory '{$zip_dir}' for zip file '{$zip_archive}' extraction does not exist.");
        }
    }
    $zip = new ZipArchive();
    $res = $zip->open($zip_archive);
    if ($res !== TRUE) {
        if (defined('SUGAR_PHPUNIT_RUNNER') || defined('SUGARCRM_INSTALL')) {
            $GLOBALS['log']->fatal(sprintf("ZIP Error(%d): Status(%s): Arhive(%s): Directory(%s)", $res, $zip->status, $zip_archive, $zip_dir));
            return false;
        } else {
            die(sprintf("ZIP Error(%d): Status(%s): Arhive(%s): Directory(%s)", $res, $zip->status, $zip_archive, $zip_dir));
        }
    }
    if ($archive_file !== null) {
        $res = $zip->extractTo($zip_dir, $archive_file);
    } else {
        $res = $zip->extractTo($zip_dir);
    }
    if ($res !== TRUE) {
        if (defined('SUGAR_PHPUNIT_RUNNER') || defined('SUGARCRM_INSTALL')) {
            $GLOBALS['log']->fatal(sprintf("ZIP Error(%d): Status(%s): Arhive(%s): Directory(%s)", $res, $zip->status, $zip_archive, $zip_dir));
            return false;
        } else {
            die(sprintf("ZIP Error(%d): Status(%s): Arhive(%s): Directory(%s)", $res, $zip->status, $zip_archive, $zip_dir));
        }
    }
    return true;
}
开发者ID:nartnik,项目名称:sugarcrm_test,代码行数:35,代码来源:php_zip_utils.php

示例11: extract

 /**
  * Extract an archived and/or compressed file
  *
  * @param  string $to
  * @return void
  */
 public function extract($to = null)
 {
     if ($this->archive->open($this->path) === true) {
         $path = null !== $to ? realpath($to) : './';
         $this->archive->extractTo($path);
         $this->archive->close();
     }
 }
开发者ID:Nnadozieomeonu,项目名称:lacecart,代码行数:14,代码来源:Zip.php

示例12: extract

 /**
  * {@inheritdoc}
  */
 public function extract($path, array $files = array())
 {
     if ($files) {
         $this->zip->extractTo($path, $files);
     } else {
         $this->zip->extractTo($path);
     }
     return $this;
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:12,代码来源:Zip.php

示例13: _extractByPhpLib

 /**
  * ZipArchive クラスによる展開
  *
  * @param $source
  * @param $target
  * @return bool
  */
 protected function _extractByPhpLib($source, $target)
 {
     if ($this->Zip->open($source) === true && $this->Zip->extractTo($target)) {
         $archivePath = $this->Zip->getNameIndex(0);
         $archivePathAry = explode(DS, $archivePath);
         $this->topArchiveName = $archivePathAry[0];
         return true;
     } else {
         return false;
     }
 }
开发者ID:baserproject,项目名称:basercms,代码行数:18,代码来源:BcZip.php

示例14: extractFileIntoFolder

 /**
  * Metodo utilizzato per estrarre i tracciati dati e immagini 
  * nella cartella import
  */
 function extractFileIntoFolder()
 {
     $zip = new \ZipArchive();
     $res = $zip->open(FOLDER_IMPORT_ROOT . FILE_ERP_DATA);
     if ($res === TRUE) {
         $zip->extractTo(FOLDER_UNZIP);
         $zip->close();
     }
     $res2 = $zip->open(FOLDER_IMPORT_ROOT . FILE_ERP_IMG);
     if ($res2 === TRUE) {
         $zip->extractTo(FOLDER_UNZIP);
         $zip->close();
     }
 }
开发者ID:addomine,项目名称:Vision-eCommerce,代码行数:18,代码来源:PSObject.php

示例15: unpackZip

 /**
  * @param string
  * @param string
  */
 private function unpackZip($zipPath, $dataPath)
 {
     if ($this->verbose) {
         $this->writeln('Unpacking pages zip file');
     }
     if (file_exists($dataPath)) {
         try {
             FileSystem::delete($dataPath);
         } catch (\Nette\IOException $e) {
             throw new \NetteAddons\InvalidStateException('Pages temp data directory already exists');
         }
     }
     $zip = new \ZipArchive();
     if ($err = $zip->open($zipPath) !== TRUE) {
         throw new \NetteAddons\InvalidStateException('Pages zip file is corrupted', $err);
     }
     if (!mkdir($dataPath, 0777, TRUE)) {
         throw new \NetteAddons\InvalidStateException('Pages temp data directory could not be created');
     }
     if (!$zip->extractTo($dataPath)) {
         throw new \NetteAddons\InvalidStateException('Pages zip file is corrupted');
     }
     $zip->close();
     unlink($zipPath);
 }
开发者ID:newPOPE,项目名称:web-addons.nette.org,代码行数:29,代码来源:PagesPresenter.php


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