how to reduce the size of the zip created with php

Asked

Viewed 834 times

1

how can I reduce the size of a file ZIP raised with PHP. I’m getting it zipped, but the size of it remains the same as I can get it down. for example I want to zip a file 2MB and when to zip I want the ZIP be less than 1MB or even a 1MB how to do this?

my code

$zip = new ZipArchive();

if( $zip->open( 'teste/sample.zip' , ZipArchive::CREATE )  === true) {
    $zip->addFile(  'teste/arqtest.pdf' , 'arqtest.pdf' );

    $zip->close();
}
  • mp3, jpg files and others already optimize the way they store information and therefore there is not much to do.

  • If it were possible to zip and have a high compression rate independent of the file then we could zip a file several times and start from a file with several gigabytes and end with a 1MB file.

1 answer

2

The algorithm zip is fixed. You cannot have a higher compression because the compression ratio depends mainly on the type of data being compressed.

For example, you will have a very good compression rate when compressing a text file containing nothing but characters A, but a compression ratio irrelevant to a file mp3, for example.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.