Search code examples
phpphp-ziparchive

ZipArchive not installed in xampp?


I have newest version of XAMPP and php version 5.6.3, but I can't use ZipArchive. I've downloaded php_zip.dll and placed it in ext dir, I've added extension=php_zip.dll but after server reset I have warming :

"Module 'zip' already loaded"

I still see error: ZipArchive not found ...

using:

$zip = new ZipArchive();

returns error:

Fatal error: Class 'Att\Controller\ZipArchive' not found in ...

Solution

  • OK, given the additional information you added upon my suggestion in the comment things become more clear now. This looks like you have a namespacing issue here: php tries to locate the class Att\Controller\ZipArchive, not the class ZipArchive. This is probably the case because you try to use the class inside a namespaced script. In that case php will assume all class names as local to the general namespace as declared at the beginning of the script unless they are noted with a specific namespace reference.

    Try makeing the class name to reference the global namespace explicitly. So instead of

    $zip = new ZipArchive();
    

    do this:

    $zip = new \ZipArchive;
    

    (Note the back slash (\) before the class name. Also you can drop the empty brackets trailing it, since they are empty.)

    Now php will try to locate a class called "ZipArchive" in the global namespace (\) and (hopefully) succeed... This is a general effect of namespacing in php and has nothing to do with the specific class you are trying to use.

    You may want to read a bit about php and namespaces. Take a look into the documentation: http://php.net/manual/en/language.namespaces.php