Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Class 'ZipArchive' not found

Status
Not open for further replies.

kristo5747

Programmer
Mar 16, 2011
41
US
Hello,

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:

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
Code:
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:

Code:
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??
 
First check that its really not enabled or installed.
run a phpinfo(); on a blank page and look for the Zip section.

If your server is a Linux box, and Zip was not compiled into the PHP installation you will need to be a root user to do this.

Alternatively you could use a third party zip class, and simply include it into your script.

Such as:

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
Quote from: dzelenika on Today at 03:27:36 PM
Is Your server on Windows, linux or some other OS?

Linux Red Hat is my server OS.

Further investigating via PHPINFO shows 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.

I am not sure what to do next....
 
assuming you have root access something like

Code:
sudo yum install php-zip php-pear

alternatively you could use the system zip functions (if installed) and create your archive via a system call (this is what I do).
 
Talked to my sysadmin.

He is gonna try `pecl install zip`.

We'll see how it goes.

Thanks for taking the time.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top