1

I am trying to implement a simple script that ZIPs up a text file but ZIPArchive() is not available on my server. Here is an example of my code:

<?php
$zip = new ZipArchive();
$filename = "./PJR.v2.zip";
if ($zip->open($filename, ZIPARCHIVE::CREATE)!==TRUE) {
    exit("cannot open <$filename>\n");
}
if ($handle = opendir('WORKDIR')) {
    while (false !== ($entry = readdir($handle))) {
        if ($entry != "." && $entry != "..") {
        $zip->addFile($entry);
        }
    }
  closedir($handle);
}
$zip->close();
?>

When I run it from the command line, I get

PHP Fatal error:  Class 'ZipArchive' not found in /users/albert/zip_POC.v2.php on line 2

This is the version info on my server:

php -v
PHP 5.1.6 (cli) (built: Nov 12 2008 11:22:53)
Copyright (c) 1997-2006 The PHP Group
Zend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies

Is there a way that I can install that class even though I am not the 'root' user??

EDIT:

PHP was not compiled on my server with ZIP support. The configure command section of PhpInfo() does not show the --enable-zip option. PECL is not installed either so I cannot workaround my problem with pecl install zip either.

gen_Eric
  • 223,194
  • 41
  • 299
  • 337
Chris
  • 1,667
  • 6
  • 34
  • 52
  • Here is a solution from earlier [Fatal error: Class 'ZipArchive' not found in](http://stackoverflow.com/questions/3872555/fatal-error-class-ziparchive-not-found-in) – Ibu Jan 24 '12 at 20:11

1 Answers1

0

If you can't install or rebuild with ZipArchive, then there's also the pure PHP PCLZip library that you could try instead.

Mark Baker
  • 209,507
  • 32
  • 346
  • 385