ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
ZipArchive.php
Go to the documentation of this file.
1 <?php
28 require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/PCLZip/pclzip.lib.php';
29 
30 
39 {
40 
46  private $_tempDir;
47 
53  private $_zip;
54 
55 
56  public function open($fileName)
57  {
58  $this->_tempDir = PHPExcel_Shared_File::sys_get_temp_dir();
59 
60  $this->_zip = new PclZip($fileName);
61 
62  return true;
63  }
64 
65 
66  public function close()
67  {
68  }
69 
70 
71  public function addFromString($localname, $contents)
72  {
73  $filenameParts = pathinfo($localname);
74 
75  $handle = fopen($this->_tempDir.'/'.$filenameParts["basename"], "wb");
76  fwrite($handle, $contents);
77  fclose($handle);
78 
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  }
86 
87  unlink($this->_tempDir.'/'.$filenameParts["basename"]);
88  }
89 
90 }