Hello,

I hope this is the right forum.

I am trying to implement a simple script that ZIPs up a text file. The problem is that I don't think the ZIPArchive is 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??

    What is ZipArchive? and where do you include it in your code? Generally a third party class would be used a long the lines of:

    require_once('ZipArchive.class.php');
    $ZA = new ZipArchive();

    You haven't included the class (or set up an __autoload) for PHP to know what it is when you try to create a new one.

      If you do a [man]phpinfo/man, do you see a table of data preceded by the header text 'Zip' ? If not, then your PHP installation most likely wasn't compiled with zip support (see [man]zip.installation[/man] and the corresponding PECL page).

        not everything in the manual is likely to be in the version of php your working with

          Write a Reply...