Search code examples
phpdirectoryzipphp-ziparchive

ZipArchives stores absolute paths


Can I zip files using relative paths?

For example:

$zip->addFile('c:/wamp/www/foo/file.txt');

the ZIP should have a directory structure like:

foo
 -> file.txt

and not:

wamp
 -> www
     -> foo
         -> file.txt

like it is by default...

ps: my full code is here (I'm using ZipArchive to compress contents of a directory into a zip file)


Solution

  • See the addFile() function definition, you can override the archive filename:

    $zip->addFile('/path/to/index.txt', 'newname.txt');