3

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 ...
Cœur
  • 37,241
  • 25
  • 195
  • 267
Mac Umatik
  • 63
  • 1
  • 9
  • zip and ZipArchive are two different things. zip (usually) referes to phps "zip" extension, which ZipArchive (usually) refers to a PECL extension based in zip. – arkascha May 31 '15 at 15:20
  • Ok, I understand, but this warming has appeared after I've added extension=php_zip.dll to php.ini (http://php.net/manual/en/zip.installation.php). So how can I use ZipArchive ? – Mac Umatik Jun 01 '15 at 07:58
  • I assume the warning (and rejection) of the library you added are the result of the fact that the zip extension already is present in your php. Probably built in (compile time) or located somewhere else. You should be able to verify that using the famous `phpinfo()` function. – arkascha Jun 01 '15 at 08:22
  • About ZipArchive: not sure what the issue is, actually. According to the documentation it is said to be included with PHP 5 >= 5.2.0 and PECL zip >= 1.1.0. Let's try to track things down. What do you mean by "I can't use ZipArchive"? What have you tried? Where does that error come from? Can you post it in full? Please add that information to the question itself, not here in comments. There is an `edit` button below the question for that. – arkascha Jun 01 '15 at 08:31
  • OK, thanks for the additional information. I posted an answer below considering this. Hope that helps to solve your issue! – arkascha Jun 01 '15 at 09:16

2 Answers2

6

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

arkascha
  • 41,620
  • 7
  • 58
  • 90
  • Glad I could help. Have fun with the next steps in your project! and give back a little here on SO :-) – arkascha Jun 01 '15 at 10:32
5

stop the xampp and then kindly remove the starting semicolon ( ; ) before ;extension=zip from your xampp/php/php.ini the following code, and start xammp again .

helvete
  • 2,455
  • 13
  • 33
  • 37
Hussam Haider
  • 51
  • 1
  • 2