views:

60

answers:

3

hi friends,

I have a problem that I install 'Archive_Zip 0.1.1' on Linux server, but when I try to run the script to create the zip file it gives the fatal error "Fatal error: Class 'ZipArchive' not found in ---" where I put the code

$zip = new ZipArchive;
var_dump($zip);
$res = $zip->open($filename, ZipArchive::OVERWRITE);
if($res !== TRUE){
    echo 'Error: Unable to create zip file';
    exit;
}
if(is_file($src)){
    $zip->addFile($src);
}else{
    //echo "<br>".dirname(__FILE__).$src;//'/install1';
    if(!is_dir($src)){
         $zip->close();
         @unlink($filename);
         echo 'Error: File not found';
         exit;
    }
    recurse_zip($src,$zip,$path_length);
}
$zip->close();
echo "<br>file name ".$filename;

but it not found the class file.

Please tell me the solution what should I do to resolve the problem. I also put php.ini file to the folder where script is, but it does not work.

A: 

For the ZipArchive class to be present, PHP needs to have the zip extension installed.

See this page for installation instructions.

Pekka
I have installed Archive_Tar and File_Archive extensions on server
parag
@parag then those aren't the right extensions, are they? The one in question here seems to be named "zip"
Pekka
I search on google and put these extensions to server. This is the first time I'm using the ziparchive or creating the zip file, So I'm not sure that are they right extensions.
parag
@parag see the page with installation instructions I linked to
Pekka
parag
@parag you will need to equip your server with the Zip extension. It's probably already installed on your local PC because you're using a development package like XAMPP or WAMP - those already come with the extension installed.
Pekka
@parag if you have no root access to your server, you will have to ask the administrator to install the extension.
Pekka
which extension is to be installed? can you please tell me the name of extension
parag
@parag it depends on the machine. On Linux, I think this is the way to go: `In order to use these functions you must compile PHP with zip support by using the --enable-zip configure option.`
Pekka
+1  A: 

1) You should require your file with ZipArchive file.

require 'path/to/file/ZipArchive.php';

2) Or use __autoload method of class. In PHP 5 it is a greate method __autoload().

function __autoload($class_name) {
    require_once $class_name . '.php';
}

$obj  = new MyClass1(); // creating an object without require.

http://www.php.net/manual/en/language.oop5.autoload.php

Alexander.Plutov
how should I include or require ZipArchive file?
parag
See my changes.
Alexander.Plutov
This is not the point. The OP is missing a PHP extension
Pekka
A: 

You also need to compile PHP with zip support. The manual says the following:

In order to use these functions you must compile PHP with zip support by using the --enable-zip configure option.

It's not enough to simply install the correct extensions on the server. Have a look at the installation instructions link Pekka posted earlier. My answer is just a clarification of his.

Jeremy
yes, but where should I run this commands on the server so that php runs with zip support
parag
Is it a server that you control? If so I believe it's part of the make command when installing PHP. If it's not a server that you control then the only option for you is to try to have the sys admin do it. Sorry I can't be more precise-I've never installed PHP on a linux server from scratch.
Jeremy