Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I change the compression level of ZipArchive?

Tags:

php

zip

Is it possible to change the compression level and/or method used by the ZipArchive class?

like image 836
Daniel Rikowski Avatar asked Dec 02 '09 14:12

Daniel Rikowski


4 Answers

This is currently not possible, according to the open bug report feature request on php.net.

like image 145
soulmerge Avatar answered Oct 04 '22 06:10

soulmerge


As stated in previous post, you can't do it with Zip. If specifying a compression level is more important than the archiving method, then PHP zlib allows it:

string gzcompress  ( string $data  [, int $level = -1  ] )

$level - The level of compression. Can be given as 0 for no compression up to 9 for maximum compression.

http://php.net/manual/en/book.zlib.php

like image 33
Indrek Avatar answered Oct 04 '22 07:10

Indrek


It seems to have been implemented / added to redistribution files in PHP 7: ZipArchive::setCompressionName and ZipArchive::setCompressionIndex. Not tested.

PS: The reason why it is set individually for files and not the entire archive is because files inside a ZIP archive are actually themself ZIP files and are just "glued" together to one "master ZIP archive".

like image 30
StanE Avatar answered Oct 04 '22 08:10

StanE


Indeed it is not possible evenin 2014 so i had to use the "exec" function with the zip command for linux :

exec("cd \"".$the_directory_you want_to_zip."\" && zip -0 -r \"".$path_zip."\" .");
like image 36
Vindic Avatar answered Oct 04 '22 06:10

Vindic