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


PHP ZipArchive::open方法代码示例

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


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

示例1: save

 /**
  * Save PHPExcel to file
  *
  * @param 	string 		$pFileName
  * @throws 	Exception
  */
 public function save($pFilename = null)
 {
     if (!is_null($this->_spreadSheet)) {
         // Garbage collect...
         foreach ($this->_spreadSheet->getAllSheets() as $sheet) {
             $sheet->garbageCollect();
         }
         // Create new ZIP file and open it for writing
         $objZip = new ZipArchive();
         // Try opening the ZIP file
         if ($objZip->open($pFilename, ZIPARCHIVE::OVERWRITE) !== true) {
             if ($objZip->open($pFilename, ZIPARCHIVE::CREATE) !== true) {
                 throw new Exception("Could not open " . $pFilename . " for writing.");
             }
         }
         // Add media
         $sheetCount = $this->_spreadSheet->getSheetCount();
         for ($i = 0; $i < $sheetCount; ++$i) {
             for ($j = 0; $j < $this->_spreadSheet->getSheet($i)->getDrawingCollection()->count(); ++$j) {
                 if ($this->_spreadSheet->getSheet($i)->getDrawingCollection()->offsetGet($j) instanceof PHPExcel_Worksheet_BaseDrawing) {
                     $imgTemp = $this->_spreadSheet->getSheet($i)->getDrawingCollection()->offsetGet($j);
                     $objZip->addFromString('media/' . $imgTemp->getFilename(), file_get_contents($imgTemp->getPath()));
                 }
             }
         }
         // Add phpexcel.xml to the document, which represents a PHP serialized PHPExcel object
         $objZip->addFromString('phpexcel.xml', $this->_writeSerialized($this->_spreadSheet, $pFilename));
         // Close file
         if ($objZip->close() === false) {
             throw new Exception("Could not close zip file {$pFilename}.");
         }
     } else {
         throw new Exception("PHPExcel object unassigned.");
     }
 }
开发者ID:sensorsix,项目名称:app,代码行数:41,代码来源:Serialized.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: 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

示例4: 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

示例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: 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

示例7: _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

示例8: fillZipWithFileContents

 /**
  * Add all file and string contents to zip file.
  *
  * @param string $zipFileUrl
  */
 private function fillZipWithFileContents($zipFileUrl)
 {
     $this->zip->open($zipFileUrl, \ZipArchive::CREATE);
     $this->finalizeSheet();
     $this->finalizeStyles();
     $this->finalizeDefaultXmls();
 }
开发者ID:nimmneun,项目名称:onesheet,代码行数:12,代码来源:Finalizer.php

示例9: __construct

 /**
  * Constructs a Zip object.
  *
  * @param string $file_path
  *   The full system path of the archive to manipulate. Only local files
  *   are supported. If the file does not yet exist, it will be created if
  *   appropriate.
  *
  * @throws \Drupal\Core\Archiver\ArchiverException
  */
 public function __construct($file_path)
 {
     $this->zip = new \ZipArchive();
     if ($this->zip->open($file_path) !== TRUE) {
         throw new ArchiverException(t('Cannot open %file_path', array('%file_path' => $file_path)));
     }
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:17,代码来源:Zip.php

示例10: save

 /**
  * Save PhpPresentation to file
  *
  * @param  string    $pFilename
  * @throws \Exception
  */
 public function save($pFilename)
 {
     if (empty($pFilename)) {
         throw new \Exception("Filename is empty.");
     }
     if (!is_null($this->presentation)) {
         // Create new ZIP file and open it for writing
         $objZip = new \ZipArchive();
         // Try opening the ZIP file
         if ($objZip->open($pFilename, \ZipArchive::CREATE) !== true) {
             if ($objZip->open($pFilename, \ZipArchive::OVERWRITE) !== true) {
                 throw new \Exception("Could not open " . $pFilename . " for writing.");
             }
         }
         // Add media
         $slideCount = $this->presentation->getSlideCount();
         for ($i = 0; $i < $slideCount; ++$i) {
             for ($j = 0; $j < $this->presentation->getSlide($i)->getShapeCollection()->count(); ++$j) {
                 if ($this->presentation->getSlide($i)->getShapeCollection()->offsetGet($j) instanceof AbstractDrawing) {
                     $imgTemp = $this->presentation->getSlide($i)->getShapeCollection()->offsetGet($j);
                     $objZip->addFromString('media/' . $imgTemp->getFilename(), file_get_contents($imgTemp->getPath()));
                 }
             }
         }
         // Add PhpPresentation.xml to the document, which represents a PHP serialized PhpPresentation object
         $objZip->addFromString('PhpPresentation.xml', $this->writeSerialized($this->presentation, $pFilename));
         // Close file
         if ($objZip->close() === false) {
             throw new \Exception("Could not close zip file {$pFilename}.");
         }
     } else {
         throw new \Exception("PhpPresentation object unassigned.");
     }
 }
开发者ID:hxsam,项目名称:PHPPresentation,代码行数:40,代码来源:Serialized.php

示例11: __construct

 public function __construct($archive_path)
 {
     $this->archive = new \ZipArchive();
     $this->archive_path = $archive_path;
     if ($this->archive->open($this->archive_path, \ZipArchive::CREATE) !== true) {
         throw new ArchiveException('Cannot create zip archive: ' . $this->archive_path);
     }
 }
开发者ID:ansarbek,项目名称:tuleap,代码行数:8,代码来源:ZipArchive.php

示例12: __construct

 /**
  * Crea un archivo ZIP
  */
 public function __construct()
 {
     # create new zip opbject
     $this->_zip = new ZipArchive();
     # create a temp file & open it
     $this->_tempfile = tempnam('.', '');
     $this->_zip->open($this->_tempfile, ZipArchive::CREATE);
 }
开发者ID:CarlosAyala,项目名称:midas-codeigniter-modulo-emergencias,代码行数:11,代码来源:Zip.php

示例13: __construct

 /**
  * ZipArchiveCreator constructor
  *
  * @param string $file Path to archive
  * @throws \Exception
  */
 public function __construct($file)
 {
     $this->zip = new \ZipArchive();
     $this->file = $file;
     if ($this->zip->open($this->file, \ZipArchive::CREATE) !== true) {
         throw new \Exception('Unable create archive');
     }
 }
开发者ID:ambient-lounge,项目名称:site,代码行数:14,代码来源:ZipArchiveCreator.php

示例14: zipOpen

 /**
  * @param string $filePath
  * @return $this
  * @throws Exception\Zip\FileOpenException
  */
 private function zipOpen($filePath)
 {
     if ($code = $this->zip->open($filePath) !== true) {
         throw new Exception\Zip\FileOpenException($filePath, $code);
     }
     $this->filePath = $filePath;
     return $this;
 }
开发者ID:tyz910,项目名称:docx-templates,代码行数:13,代码来源:Document.php

示例15: __construct

 /**
  * Constructor
  *
  * @param string  $filename  Name of the .zip archive
  * @throws Exception
  */
 public function __construct($filename)
 {
     $this->filename = $filename;
     $this->ziparchive = new ZipArchive();
     if ($this->ziparchive->open($filename) !== true) {
         throw new Exception('Error opening ' . $filename);
     }
 }
开发者ID:nnnnathann,项目名称:piwik,代码行数:14,代码来源:ZipArchive.php


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