16

I've just downloaded PHPExcel package and I tried to import an Excel spreadsheet, but all I get is an error ZipArchive not found. I work on Windows, but server is on Linux. I checked php.ini to see if php_zip is disabled, but it wasn't even there.

I tried installing it with PECL: $ pecl install zip

No releases availble for package "pecl.php.net/zip" Cannot initialize 'channel://pecl.php.net/zip', invalid or missing package file Package "channel://pecl.php.net/zip" is not valid install failed

And also pear install zip-1.10.2.tgz but recieved pretty much the same message.

I don't have root permission to the server, maybe that's the case? Anyways, could you help me with this?

whiteestee
  • 301
  • 1
  • 4
  • 12
  • 1
    I think Mark Baker may help you, what version of PHPExcel are you using? lastest release? – briosheje Aug 07 '14 at 07:52
  • Yep, I use PHPExcel 1.8.0 – whiteestee Aug 07 '14 at 07:54
  • You're apparently not the first who got this error: https://phpexcel.codeplex.com/discussions/233977 . However, from what I'm reading, you also need **permissions**: http://prntscr.com/4adzsp . Have you got all the extensions required enabled? can you change permissions to PHPExcel's folder? – briosheje Aug 07 '14 at 07:59
  • I don't even have php_zip line in php.ini file and adding it by myself... well... surprisingly did not work. I have permission to PHPExcel folder, but PHP requires ZipArchive installed and I can't figure out how to install it. – whiteestee Aug 07 '14 at 08:09
  • What version of PHP are you using? In the requirements, it is said that you need at least the php version 5.2 . I suppose that if the php_zip line was not present in your PHP.ini, then I suspect that the extension is not present at all (and it would explain why it is not working). Perhaps try using a different version of PHP excel, maybe an older one... – briosheje Aug 07 '14 at 08:15
  • I have PHP 5.2.5. I think I would need to recompile PHP with php_zip, but I can't do this ATM because I don't have permissions... – whiteestee Aug 07 '14 at 08:16
  • Then you may add and compile the ziparchive extention, or perhaps, as I said above, use an older version of PHPExcel. I'm personally using PHPExcel 1.7.6 and php 5.0; in my PHP.ini file I don't have aswell the php_zip line and everything is working.. Perhaps try using 1.7.6 for instance? https://phpexcel.codeplex.com/releases/view/45412 – briosheje Aug 07 '14 at 08:21
  • Wait, I just saw this: http://prntscr.com/4ae5jk and also this: http://prntscr.com/4ae5oq . Try, when you include PHPExcel, to do this: `PHPExcel_Settings::setZipClass(PHPExcel_Settings::PCLZIP);`. It seems that this is related to Excel2007. I probably had no issues yet because I was NOT using any Excel2007 worksheets but just Excel2003 worksheets.. – briosheje Aug 07 '14 at 08:31
  • I included `PHPExcel_Settings::setZipClass(PHPExcel_Settings::PCLZIP);` before and it didn't work. But PHPExcel 1.7.6 seems to be working, at least it doesn't display `ZipArchive not found` anymore. So thanks `briosheje` for your help!!! – whiteestee Aug 07 '14 at 08:36
  • 1
    So, perhaps, you don't have both extensions (PCLZIP and ZipArchive). I don't think you can get any further without these extention, but I would suggest you to directly contact Mark Baker here in stackoverflow, as he is one of the developpers of phpexcel :). Edit: Oh, okay, then try working with it, perhaps it will work, but I would suggest you in any case to contact mark baker for such a case, perhaps he has the solution for such issue :) – briosheje Aug 07 '14 at 08:38

7 Answers7

47

Certain spreadsheet file formats, such as OfficeOpenXML used as the default format by Excel 2007 and above, require ZipArchive. In most recent versions of PHP, ZipArchive is always available, but prior to PHP 5.3 it needed to be manually installed as a PHP extension.

As @briosheje says If you don't have ZipArchive installed/enabled for your PHP, then you can use

PHPExcel_Settings::setZipClass(PHPExcel_Settings::PCLZIP);

PCLZip is included in the PHPExcel distribution as an alternative to PHP's built-in ZipArchive class, though it is quite a bit slower. Enabling PCLZip allows you to work with zip-based spreadsheet formats even without ZipArchive.

However, when we first bundled PCLZip (originally in PHPExcel 1.7.6), it was only an option when writing zip-based formats, not when reading them. We changed that in PHPExcel 1.8.0, so enabling PCLZip now allows you to read zip-based formats as well as writing them.

The PHPEXcel Reader documentation details the different spreadsheet formats, and explains which ones are zip-based.

Mark Baker
  • 209,507
  • 32
  • 346
  • 385
  • 1
    I have `PHP 7.0.8` on server and `PHP 5.5.9` on localhost with version `1.8.0` for PHPExcel on both. Everything works perfect on `localhost` but not on our server. Initially I was getting `Class 'ZipArchive' not found in Reader/Excel2007.php:94`error. So I included `PHPExcel_Settings::setZipClass(PHPExcel_Settings::ZIPARCHIVE);`. But then I am getting `Uncaught Error: Call to undefined method PHPExcel_Shared_ZipArchive::statName() in Reader/OOCalc.php:89`. I also tried installing 'zip' module by `pecl install zip`. But it is also not working. Can you provide some pointers? – Chaitanya Jan 09 '17 at 18:30
  • 14
    `sudo apt-get install php7.0-zip` worked for me after all these steps... – Chaitanya Jan 09 '17 at 19:29
  • 2
    @Chaitanya solution is working for me on php 7 - Ubuntu 16.04. The accepted answer was working up to php 5.6 on Debian Jessie. – Sir_Faenor Jan 10 '17 at 11:24
  • For sake of completeness, It also could be a conflict with older PHP installation. For example once I tried by removing PHP5 installation and reinstalling PHP7 version and everything worked fine – Chris Feb 15 '17 at 14:26
  • This made my day. Thanks – Muhammad Noman Jan 31 '19 at 10:24
14

In my case I have PHP 5.4
Upon using PHPExcel, I encountered this exception.

FatalErrorException in Excel2007.php line 94: Class 'ZipArchive' not found

Solved it by appending this line on PHPExcel/Reader/Excel2007.php

PHPExcel_Settings::setZipClass(PHPExcel_Settings::PCLZIP);

before invoking the getZipClass method.

$zipClass = PHPExcel_Settings::getZipClass();
Kent Aguilar
  • 5,048
  • 1
  • 33
  • 20
8

You have to install extension for php called like php-zip and zip program on your linux machine.

Stas Panyukov
  • 348
  • 3
  • 8
5

I found a simple solution:

  1. login to your cpanel
  2. go to software > select PHP version
  3. select PHP version 7.0 and click set as current button
  4. check zip checkbox
  5. click save

Now you refresh your site to download excel file

Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
4

If you are using cpanel you may have zip extension installed but not activate. You need to active it. For this case you need to go to cpanel > inside software section > click on PHP version. Then find zip and check it. Now save. Enable zip extension

Refresh your application page.

Shafiq
  • 963
  • 8
  • 4
2

The easy way is to insert : PHPExcel_Settings::setZipClass(PHPExcel_Settings::PCLZIP); in your script just before calling $objWriter->save();

This worked for me.

regards!

hkn
  • 1,453
  • 19
  • 21
  • That is [what Mark Baker answered](https://stackoverflow.com/a/25181889/479156) more than four years ago. Is this intended as an actual answer, or just a confirmation that it works? And if it is meant as an answer, please explain what additional value it has over Mark's answer. If it doesn't have any, please consider deleting it as it serves no additional value. – Ivar Jan 16 '19 at 14:41
0

For me, this one worked

sudo apt install php7.1-zip
alex toader
  • 2,300
  • 1
  • 17
  • 20