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


PHP Settings::getZipClass方法代码示例

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


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

示例1: __construct

 /**
  * Create a new Template Object
  *
  * @param string $strFilename
  * @throws \PhpOffice\PhpWord\Exception\Exception
  */
 public function __construct($strFilename)
 {
     $this->tempFileName = tempnam(sys_get_temp_dir(), '');
     if ($this->tempFileName === false) {
         throw new Exception('Could not create temporary file with unique name in the default temporary directory.');
     }
     // Copy the source File to the temp File
     if (!copy($strFilename, $this->tempFileName)) {
         throw new Exception("Could not copy the template from {$strFilename} to {$this->tempFileName}.");
     }
     $zipClass = Settings::getZipClass();
     $this->zipClass = new $zipClass();
     $this->zipClass->open($this->tempFileName);
     // Find and load headers and footers
     $index = 1;
     while ($this->zipClass->locateName($this->getHeaderName($index)) !== false) {
         $this->headerXMLs[$index] = $this->zipClass->getFromName($this->getHeaderName($index));
         $index++;
     }
     $index = 1;
     while ($this->zipClass->locateName($this->getFooterName($index)) !== false) {
         $this->footerXMLs[$index] = $this->zipClass->getFromName($this->getFooterName($index));
         $index++;
     }
     $this->documentXML = $this->zipClass->getFromName('word/document.xml');
 }
开发者ID:kaantunc,项目名称:MYK-BOR,代码行数:32,代码来源:Template.php

示例2: __construct

 /**
  * Create new instance
  */
 public function __construct()
 {
     $this->usePclzip = Settings::getZipClass() != 'ZipArchive';
     if ($this->usePclzip) {
         if (!defined('PCLZIP_TEMPORARY_DIR')) {
             define('PCLZIP_TEMPORARY_DIR', sys_get_temp_dir() . '/');
         }
         require_once 'PCLZip/pclzip.lib.php';
     }
 }
开发者ID:hcvcastro,项目名称:pxp,代码行数:13,代码来源:ZipArchive.php

示例3: getBase64ImageData

 /**
  * Get Base64 image data
  *
  * @return string|null
  */
 private function getBase64ImageData(ImageElement $element)
 {
     $source = $element->getSource();
     $imageType = $element->getImageType();
     $imageData = null;
     $imageBinary = null;
     $actualSource = null;
     // Get actual source from archive image or other source
     // Return null if not found
     if ($element->getSourceType() == ImageElement::SOURCE_ARCHIVE) {
         $source = substr($source, 6);
         list($zipFilename, $imageFilename) = explode('#', $source);
         $zipClass = \PhpOffice\PhpWord\Settings::getZipClass();
         $zip = new $zipClass();
         if ($zip->open($zipFilename) !== false) {
             if ($zip->locateName($imageFilename)) {
                 $zip->extractTo($this->parentWriter->getTempDir(), $imageFilename);
                 $actualSource = $this->parentWriter->getTempDir() . DIRECTORY_SEPARATOR . $imageFilename;
             }
         }
         $zip->close();
     } else {
         $actualSource = $source;
     }
     if (is_null($actualSource)) {
         return null;
     }
     // Read image binary data and convert into Base64
     if ($element->getSourceType() == ImageElement::SOURCE_GD) {
         $imageResource = call_user_func($element->getImageCreateFunction(), $actualSource);
         ob_start();
         call_user_func($element->getImageFunction(), $imageResource);
         $imageBinary = ob_get_contents();
         ob_end_clean();
     } else {
         if ($fileHandle = fopen($actualSource, 'rb', false)) {
             $imageBinary = fread($fileHandle, filesize($actualSource));
             fclose($fileHandle);
         }
     }
     if (!is_null($imageBinary)) {
         $base64 = chunk_split(base64_encode($imageBinary));
         $imageData = 'data:' . $imageType . ';base64,' . $base64;
     }
     return $imageData;
 }
开发者ID:kaantunc,项目名称:MYK-BOR,代码行数:51,代码来源:Image.php

示例4: getDomFromZip

 /**
  * Get DOMDocument from ZipArchive
  *
  * @param string $zipFile
  * @param string $xmlFile
  * @return \DOMDocument|false
  */
 public function getDomFromZip($zipFile, $xmlFile)
 {
     if (file_exists($zipFile) === false) {
         throw new Exception('Cannot find archive file.');
     }
     $zipClass = Settings::getZipClass();
     $zip = new $zipClass();
     $canOpen = $zip->open($zipFile);
     if ($canOpen === false) {
         throw new Exception('Cannot open archive file.');
     }
     $contents = $zip->getFromName($xmlFile);
     $zip->close();
     if ($contents === false) {
         return false;
     } else {
         $this->dom = new \DOMDocument();
         $this->dom->loadXML($contents);
         return $this->dom;
     }
 }
开发者ID:kaantunc,项目名称:MYK-BOR,代码行数:28,代码来源:XMLReader.php

示例5: readRelationships

 /**
  * Read all relationship files
  *
  * @param string $docFile
  * @return array
  */
 private function readRelationships($docFile)
 {
     $relationships = array();
     // _rels/.rels
     $relationships['main'] = $this->getRels($docFile, '_rels/.rels');
     // word/_rels/*.xml.rels
     $wordRelsPath = 'word/_rels/';
     $zipClass = Settings::getZipClass();
     $zip = new $zipClass();
     if ($zip->open($docFile) === true) {
         for ($i = 0; $i < $zip->numFiles; $i++) {
             $xmlFile = $zip->getNameIndex($i);
             if (substr($xmlFile, 0, strlen($wordRelsPath)) == $wordRelsPath && substr($xmlFile, -1) != '/') {
                 $docPart = str_replace('.xml.rels', '', str_replace($wordRelsPath, '', $xmlFile));
                 $relationships[$docPart] = $this->getRels($docFile, $xmlFile, 'word/');
             }
         }
         $zip->close();
     }
     return $relationships;
 }
开发者ID:kaantunc,项目名称:MYK-BOR,代码行数:27,代码来源:Word2007.php

示例6: testSetGetZipClass

 /**
  * Test set/get zip class
  */
 public function testSetGetZipClass()
 {
     $this->assertEquals(Settings::ZIPARCHIVE, Settings::getZipClass());
     $this->assertTrue(Settings::setZipClass(Settings::PCLZIP));
     $this->assertFalse(Settings::setZipClass('foo'));
 }
开发者ID:kaantunc,项目名称:MYK-BOR,代码行数:9,代码来源:SettingsTest.php

示例7: getArchiveImageSize

 /**
  * Get image size from archive
  *
  * @param string $source
  * @return array|null
  */
 private function getArchiveImageSize($source)
 {
     $imageData = null;
     $source = substr($source, 6);
     list($zipFilename, $imageFilename) = explode('#', $source);
     $tempFilename = tempnam(sys_get_temp_dir(), 'PHPWordImage');
     $zipClass = Settings::getZipClass();
     $zip = new $zipClass();
     if ($zip->open($zipFilename) !== false) {
         if ($zip->locateName($imageFilename)) {
             $imageContent = $zip->getFromName($imageFilename);
             if ($imageContent !== false) {
                 file_put_contents($tempFilename, $imageContent);
                 $imageData = @getimagesize($tempFilename);
                 unlink($tempFilename);
             }
         }
         $zip->close();
     }
     return $imageData;
 }
开发者ID:kaantunc,项目名称:MYK-BOR,代码行数:27,代码来源:Image.php

示例8: addFileToPackage

 /**
  * Add file to package
  *
  * Get the actual source from an archive image
  *
  * @param mixed $objZip
  * @param string $source
  * @param string $target
  */
 protected function addFileToPackage($objZip, $source, $target)
 {
     $isArchive = strpos($source, 'zip://') !== false;
     $actualSource = null;
     if ($isArchive) {
         $source = substr($source, 6);
         list($zipFilename, $imageFilename) = explode('#', $source);
         $zipClass = \PhpOffice\PhpWord\Settings::getZipClass();
         $zip = new $zipClass();
         if ($zip->open($zipFilename) !== false) {
             if ($zip->locateName($imageFilename)) {
                 $zip->extractTo($this->getTempDir(), $imageFilename);
                 $actualSource = $this->getTempDir() . DIRECTORY_SEPARATOR . $imageFilename;
             }
         }
         $zip->close();
     } else {
         $actualSource = $source;
     }
     if (!is_null($actualSource)) {
         $objZip->addFile($actualSource, $target);
     }
 }
开发者ID:kaantunc,项目名称:MYK-BOR,代码行数:32,代码来源:AbstractWriter.php


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