Upload zip without zziplib

Hi, this is not realy a feature request because i've fixed it myself. I dont have zziplib on my server so i've made a hack that uses pclzip.lib and the zlib library.

what you do is upload pclzip.lib.php to your server in the zen/ foler(same folder as e.g. functions.php)
Then there is a little hack to functions.php
Replace the original function unzip();
`

function unzip($file, $dir) {

$zip = zip_open($file);

if ($zip) {

while ($zip_entry = zip_read($zip)) {

// Skip non-images in the zip file.

if (!is_image(zip_entry_name($zip_entry))) continue;

if (zip_entry_open($zip, $zip_entry, "r")) {

$buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));

$path_file = str_replace("/",DIRECTORY_SEPARATOR, $dir . '/' . zip_entry_name($zip_entry));

$fp = fopen($path_file, "w");

fwrite($fp, $buf);

fclose($fp);

zip_entry_close($zip_entry);

}

}

zip_close($zip);

}

}

`
With:
`

function unzip($file, $dir)

{ //check if zziplib is installed

if(function_exists('zip_open()'))

{

$zip = zip_open($file);

if ($zip) {

while ($zip_entry = zip_read($zip)) {

// Skip non-images in the zip file.

if (!is_image(zip_entry_name($zip_entry))) continue;

if (zip_entry_open($zip, $zip_entry, "r")) {

$buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));

$path_file = str_replace("/",DIRECTORY_SEPARATOR, $dir . '/' . zip_entry_name($zip_entry));

$fp = fopen($path_file, "w");

fwrite($fp, $buf);

fclose($fp);

zip_entry_close($zip_entry);

}

}

zip_close($zip);

}

}else{

// Use Zlib

require_once('pclzip.lib.php');

$zip = new PclZip($file);

if ($zip->extract(PCLZIP_OPT_PATH, $dir, PCLZIP_OPT_REMOVE_ALL_PATH) == 0) {

die("Error : ".$zip->errorInfo(true));

}

}

}

`

I think this should be included in the next releace.

A real feature request is a function to zip your images for batch download maby.

Alex

Comments

  • balld Member
    eelay,

    Great! This code snippet works wonders... I think it should be integrated into the standard product.

    Side note, you might need to copy the entire revised function, instead of the highlighted parts shown above.

    Thanks,
    Damian
Sign In or Register to comment.