Search code examples
phpzipzlib

PHP - create standard zip file with zlib


I have just now discovered that my hosting server does not support the ZIP class for PHP.

However, it has the Zlib installed and supported .

Is there any library / function / hack / class / that will let me handle ZIP files on such a server ?

Basically I want to create zip files. I am afraid my users will be scared of the GZ extension and i would like to serve them ZIP extension (that they will open normally on win systems) ?

(please do not tell me to change hosting - I already know I have to , but it will take time and the thing is quite urgent..)

UPDATE I . thanks to @Mark Baker - i was able to extract a file with the pclzip class and this simple code

<?php

 include('pclzip.lib.php');
  $archive = new PclZip('wp.zip');
  $location = $_SERVER['DOCUMENT_ROOT'];
  if ($archive->extract(PCLZIP_OPT_PATH, $location ,
                        PCLZIP_OPT_REMOVE_PATH, 'install/release') == 0) {
    die("Error : ".$archive->errorInfo(true));
  }
?>

(I just wanted to post the code here , it was too lng for comment , and I did not wanted to post another answer )

Still did not tested the creation, but if it works the same - then I really want to kiss the developers of that class ! :-)


Solution

  • Zlib doesn't help you create zip files.

    As an alternative to your missing ZipArchive, you might take a look at the PCLZip library. This is pure PHP, so no need for additional extensions, and allows you to create zip files without ZipArchive.