This project is read-only.

Using ZipArchive instead of PEARs Archive_Zip

May 21, 2009 at 5:05 PM

A quick code change I made to skip PEARs if you don't have it. Replace this code:

    $obj = new Archive_Zip("$path$name.docx");
    $files = array('word/document.xml','[Content_Types].xml','_rels/.rels');
    if($this->_Styles) {
      $this->_Styles->SaveDocument('', 'word/');
      file_put_contents('word/_rels/document.xml.rels', $DocRel);
      $files[] = 'word/styles.xml';
      $files[] = 'word/_rels/document.xml.rels';
    }
    $obj->create($files);

 

With this:

    $obj = new ZipArchive();
    $obj_filename = "$path$name.docx";

    $obj->open($obj_filename, ZIPARCHIVE::OVERWRITE);

    $obj->addFile('word/document.xml', 'word/document.xml');
    $obj->addFile('[Content_Types].xml', '[Content_Types].xml');
    $obj->addFile('_rels/.rels', '_rels/.rels');

    if($this->_Styles) {
      $this->_Styles->SaveDocument('', 'word/');
      file_put_contents('word/_rels/document.xml.rels', $DocRel);
      $obj->addFile('word/styles.xml', 'word/styles.xml');
      $obj->addFile('word/_rels/document.xml.rels', 'word/_rels/document.xml.rels');
    }
    $obj->close();

 

The variables are kept the same so there is no confusion when comparing and debugging compared to the original.