Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHPExcel ZipArchive not found

Tags:

php

phpexcel

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?

like image 664
whiteestee Avatar asked Aug 07 '14 07:08

whiteestee


6 Answers

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.

like image 140
Mark Baker Avatar answered Oct 02 '22 13:10

Mark Baker


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();
like image 36
Kent Aguilar Avatar answered Oct 02 '22 13:10

Kent Aguilar


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

like image 26
Stas Panyukov Avatar answered Oct 02 '22 13:10

Stas Panyukov


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

like image 37
Raghavendra BK Avatar answered Oct 02 '22 12:10

Raghavendra BK


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.

like image 35
Shafiq Avatar answered Oct 02 '22 13:10

Shafiq


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!

like image 41
Jean claude Nshimirimana Avatar answered Oct 02 '22 14:10

Jean claude Nshimirimana