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


PHP Converter::save方法代码示例

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


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

示例1: generateArchive

 /**
  * Generates archive of documents based on specified data.
  *
  * @param array  $data array where each element is data for one document
  * @param string $path where to save generated archive
  * @param Converter $converter OPTIONAL document converter
  */
 public function generateArchive($data, $path, $converter = null)
 {
     //Files to be deleted after creating archive
     $cleanup = array();
     //Create directory if nonexistent
     @mkdir(dirname($path), 0770, true);
     //Prepare result archive
     $archive = new \ZipArchive();
     if (!$archive->open($path, \ZipArchive::CREATE)) {
         throw new \Exception("Failed to open result archive.");
     }
     //Create documents and add them to archive
     foreach ($data as $index => $docdata) {
         $ext = $this->template->getExtension();
         //Generate file
         $file = "{$this->tmp}/document{$index}.{$ext}";
         $document = $this->generate($docdata);
         //Convert if needed
         if ($converter) {
             $converter->save($document, $file);
             $ext = $converter->getExtension();
         } else {
             $document->save($file);
         }
         //Remove this file after we're done
         $cleanup[] = $file;
         //Put to archive
         $archive->addFile($file, "document{$index}.{$ext}");
     }
     //Write documents to archive
     $archive->close();
     //Remove temp files, has to be done after closing archive
     foreach ($cleanup as $file) {
         unlink($file);
     }
     //Check if archive was really created
     if (!file_exists($path)) {
         throw new \Exception("Failed to create result archive.");
     }
 }
开发者ID:bezirovoviku,项目名称:temgen,代码行数:47,代码来源:Generator.php


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