PHP ZipArchive, how to increase compression rate?
Get the solution ↓↓↓I'm using PHP ZipArchive for compressing folder in PHP.
The files and the subfolders are well added to the archive, but I would like to know how to increase the compression level of the archive.
The following code is based on the exemple of this commit : https://github.com/php/php-src/commit/3a55ea02
$zip = new ZipArchive();
$filename = "output/a.zip";
if (!$zip->open($filename, ZIPARCHIVE::CREATE | ZipArchive::OVERWRITE)) {
exit("cannot open <$filename>\n");
}
$zip->addFromString("testfilephp.txt", "#1 This is a test string added as testfilephp.txt.\n");
$zip->addFile('output/done/monday/pdftest.pdf', 'test.pdf');
$zip->setCompressionName("test.pdf", ZipArchive::CM_DEFLATE, 6);
$zip->setCompressionIndex(2, ZipArchive::CM_DEFLATE, 6);
$zip->close();
The compression is not enougth.
- Archive weight : 7 690 288 bytes
- PDF File"output/done/monday/pdftest.pdf" weight : 7 809 870 bytes
For this exemple, I would like that the archive weight be less than 5 000 000 bytes.
Is any anyone hase a solution for define a real compression level ?
Thanks by advance for your help and have a good week.
MickaГ«l
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: an exception occurred in the driver: could not find driver
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.