Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)

like image 659
Alex Avatar asked Dec 06 '22 11:12

Alex


1 Answers

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

$zip->addFile('/path/to/index.txt', 'newname.txt');
like image 158
Alex Howansky Avatar answered Dec 09 '22 01:12

Alex Howansky