Welcome Guest, Not a member yet? Register   Sign In
Improved Zip Encoding Library
#1

[eluser]PoetaWD[/eluser]
THIS IS A GREAT DROP-IN REPLACEMENT FOR CI BUILT-IN ZIP ENCODING CLASS.

If you use that library, I really encourage you to UPDATE.


The main additions are:

- The ability to STREAM data, and create HUGE ZIP files.
- The ability to set comments for the generated ZIP files.
- Improved Performance !


Note: I am note the author of this class. I am just sharing.


I had some memory troubles with the built-in CI Zip Encoding Library.

I spent almost a day looking for this solution because I use a SHARED HOSTING ACCOUNT that limits the PHP MEMORY USAGE to 64M.

The main problem is that the Built-in class create a variable and put ALL the data that will be included in the ZIP file in that variable. Just imagine creating a 1GB zipe file ! You would need LOTS of memory to do so.

I am going to create a USER GUIDE ci styled. Whyle I dont make it, here are some examples:

Example 1 - Simple Usage:
Code:
$this->load->library("myzip");

$fileTime = date("D, d M Y H:i:s T");

$this->myzip->setComment("Example Zip file.\nCreated on " . date('l jS \of F Y h:i:s A'));
$this->myzip->addFile("Hello World!", "hello.txt");


$this->myzip->sendZip("ZipExample1.zip");


Example 2 - Stream Data and compress BIG files:
Code:
$this->load->library("myzip");

// Example. Zip all .html files in the current directory and save to current directory.
// Make a copy, also to the current dir, for good measure.
$mem = ini_get('memory_limit');
$extime = ini_get('max_execution_time');

//ini_set('memory_limit', '512M');
ini_set('max_execution_time', 120);

$fileTime = date("D, d M Y H:i:s T");

$chapter1 = "Chapter 1\n"
. "Lorem ipsum\n"
. "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec magna lorem, mattis sit amet porta vitae, consectetur ut eros. Nullam id mattis lacus. In eget neque magna, congue imperdiet nulla. Aenean erat lacus, imperdiet a adipiscing non, dignissim eget felis. Nulla facilisi. Vivamus sit amet lorem eget mauris dictum pharetra. In mauris nulla, placerat a accumsan ac, mollis sit amet ligula. Donec eget facilisis dui. Cras elit quam, imperdiet at malesuada vitae, luctus id orci. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Pellentesque eu libero in leo ultrices tristique. Etiam quis ornare massa. Donec in velit leo. Sed eu ante tortor.\n";

$this->myzip->setComment("Example Zip file for Large file sets.\nCreated on " . date('l jS \of F Y h:i:s A'));
$this->myzip->addFile("Hello World!\r\n", "Hello.txt");

$this->myzip->openStream("big one3.txt");
$this->myzip->addStreamData($chapter1."\n\n\n");
$this->myzip->addStreamData($chapter1."\n\n\n");
$this->myzip->addStreamData($chapter1."\n\n\n");
$this->myzip->closeStream();

$this->myzip->addDirectory("Empty Dir");

// For this test you need to create a large text file called "big one1.txt"
if (file_exists("big one1.txt")) {
    $this->myzip->addLargeFile("big one1.txt", "big one2a.txt");
    
    $this->myzip->addLargeFile("big one1.txt", "big one2b.txt");
}

$this->myzip->finalize(); // as we are not using getZipData or getZipFile, we need to call finalize ourselves.
$this->myzip->sendZip("ZipExample3.zip");

I really hope this help some other people like it helped me.

The original class was found on: http://www.phpclasses.org/package/6110-P...ormat.html




Theme © iAndrew 2016 - Forum software by © MyBB