PHPExcel_Shared_ZipArchive
[ class tree: PHPExcel_Shared_ZipArchive ] [ index: PHPExcel_Shared_ZipArchive ] [ all elements ]

Source for file ZipArchive.php

Documentation is available at ZipArchive.php

  1. <?php
  2. /**
  3.  * PHPExcel
  4.  *
  5.  * Copyright (c) 2006 - 2011 PHPExcel
  6.  *
  7.  * This library is free software; you can redistribute it and/or
  8.  * modify it under the terms of the GNU Lesser General Public
  9.  * License as published by the Free Software Foundation; either
  10.  * version 2.1 of the License, or (at your option) any later version.
  11.  *
  12.  * This library is distributed in the hope that it will be useful,
  13.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15.  * Lesser General Public License for more details.
  16.  *
  17.  * You should have received a copy of the GNU Lesser General Public
  18.  * License along with this library; if not, write to the Free Software
  19.  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  20.  *
  21.  * @category   PHPExcel
  22.  * @package    PHPExcel_Shared_ZipArchive
  23.  * @copyright  Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
  24.  * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt    LGPL
  25.  * @version    1.7.6, 2011-02-27
  26.  */
  27.  
  28. require_once PHPEXCEL_ROOT 'PHPExcel/Shared/PCLZip/pclzip.lib.php';
  29.  
  30.  
  31. /**
  32.  * PHPExcel_Shared_ZipArchive
  33.  *
  34.  * @category   PHPExcel
  35.  * @package    PHPExcel_Shared_ZipArchive
  36.  * @copyright  Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
  37.  */
  38. {
  39.  
  40.     /**
  41.      * Temporary storage directory
  42.      *
  43.      * @var string 
  44.      */
  45.     private $_tempDir;
  46.  
  47.     /**
  48.      * Zip Archive Stream Handle
  49.      *
  50.      * @var string 
  51.      */
  52.     private $_zip;
  53.  
  54.  
  55.     public function open($fileName)
  56.     {
  57.         $this->_tempDir PHPExcel_Shared_File::sys_get_temp_dir();
  58.  
  59.         $this->_zip new PclZip($fileName);
  60.  
  61.         return true;
  62.     }
  63.  
  64.  
  65.     public function close()
  66.     {
  67.     }
  68.  
  69.  
  70.     public function addFromString($localname$contents)
  71.     {
  72.         $filenameParts pathinfo($localname);
  73.  
  74.         $handle fopen($this->_tempDir.'/'.$filenameParts["basename"]"wb");
  75.         fwrite($handle$contents);
  76.         fclose($handle);
  77.  
  78.         $res $this->_zip->add($this->_tempDir.'/'.$filenameParts["basename"],
  79.                                 PCLZIP_OPT_REMOVE_PATH$this->_tempDir,
  80.                                 PCLZIP_OPT_ADD_PATH$filenameParts["dirname"]
  81.                                );
  82.         if ($res == 0{
  83.             throw new Exception("Error zipping files : " $this->_zip->errorInfo(true));
  84.         }
  85.  
  86.         unlink($this->_tempDir.'/'.$filenameParts["basename"]);
  87.     }
  88.  
  89. }

Documentation generated on Sun, 27 Feb 2011 16:37:32 -0800 by phpDocumentor 1.4.3