File Source for ZipArchive.php

PHPExcel_Shared_ZipArchive

# 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. */
28. require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/PCLZip/pclzip.lib.php';
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. class PHPExcel_Shared_ZipArchive
39. {
41. /**
42. * Temporary storage directory
43. *
44. * @var string
45. */
46. private $_tempDir;
48. /**
49. * Zip Archive Stream Handle
50. *
51. * @var string
52. */
53. private $_zip;
56. public function open($fileName)
57. {
58. $this->_tempDir = PHPExcel_Shared_File:: sys_get_temp_dir();
60. $this->_zip = new PclZip($fileName);
62. return true;
63. }
66. public function close()
67. {
68. }
71. public function addFromString($localname, $contents)
72. {
73. $filenameParts = pathinfo($localname);
75. $handle = fopen($this->_tempDir.'/'.$filenameParts["basename"], "wb");
76. fwrite($handle, $contents);
77. fclose($handle);
79. $res = $this->_zip->add($this->_tempDir.'/'.$filenameParts["basename"],
80. PCLZIP_OPT_REMOVE_PATH, $this->_tempDir,
81. PCLZIP_OPT_ADD_PATH, $filenameParts["dirname"]
82. );
83. if ($res == 0) {
84. throw new Exception("Error zipping files : " . $this->_zip->errorInfo(true));
85. }
87. unlink($this->_tempDir.'/'.$filenameParts["basename"]);
88. }
90. }

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