ZipArchive

I’m trying to use ZipArchive at the command line to zip a number of xml files which together comprise an office open XML document (a .docx file). One of the required xml files is _rels.rels.xml. For some reason PHP doesn’t like that file–the dot rels.xml. If I take out the line in bold below, things are fine. But if I leave that line in, I get no zip file. Any clues?

<?php $zip = new ZipArchive; $res = $zip->open('c:\php\myscripts\testDoc1test.zip', ZipArchive::CREATE); if ($res === TRUE) { echo 'ok'; } else { echo 'failed'; } $zip->addFile('c:\php\myscripts\testDoc1\[Content_Types].xml', '[Content_Types].xml'); [b] $zip->addFile('c:\php\myscripts\testDoc1\_rels\.rels.xml', '_rels\.rels.xml'); [/b] $zip->addFile('c:\php\myscripts\testDoc1\docProps\app.xml', 'docProps\app.xml'); $zip->addFile('c:\php\myscripts\testDoc1\docProps\core.xml', 'docProps\core.xml'); $zip->addFile('c:\php\myscripts\testDoc1\word\document.xml', 'word\document.xml'); $zip->addFile('c:\php\myscripts\testDoc1\word\fontTable.xml', 'word\fontTable.xml'); $zip->addFile('c:\php\myscripts\testDoc1\word\numbering.xml', 'word\numbering.xml'); $zip->addFile('c:\php\myscripts\testDoc1\word\settings.xml', 'word\settings.xml'); $zip->addFile('c:\php\myscripts\testDoc1\word\styles.xml', 'word\styles.xml'); $zip->addFile('c:\php\myscripts\testDoc1\word\webSettings.xml', 'word\webSettings.xml'); $zip->addFile('c:\php\myscripts\testDoc1\word\_rels\document.xml.rels', 'word\_rels\document.xml.rels'); $zip->addFile('c:\php\myscripts\testDoc1\word\theme\theme1.xml', 'word\theme\theme1.xml'); $zip->close(); ?>

Probably combination backslash-dot . is interpreted by ZipArchive wrongly as directory… Try to use forward slashes in the paths, like this:

[php]
$zip->addFile(‘c:/php/myscripts/testDoc1/_rels/.rels.xml’, ‘_rels/.rels.xml’);
[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service