Solving undefined ZipArchive and undefined variable contents when using PHP Excel

As you know that PHP Excel was deprecated in 2017 and in 2019 it was officially archived. But, before we go to upgrade it to spreedsheet or another library, sometimes we need to solve some project or old project that used this library.

Well, I just want to tell you my experiences when using this library for my project. Its about error ZipArchive not found.

When I browse to the internet, I found that someone gave the solution by upgrading it to the latest version (before deprecated, 1.8.1), but in my case its also not wokring properly.

So, after I try diferent ways, the error was solved by adding this line:


before you use the library.

Well, the error about ZipArchive that not found was gone. I think in this case we change the source to use system zip/php zip instead the zip from the library? Correct me if I wrong. Because before that I allready try to install php zip to my server.

Forget it. But why it still not working? Then I found something error like this one:

Message: Undefined variable: contentsFilename: Shared/ZipArchive.php

StackOverflow not answer me, then I try different method to call the library and it working well. What I did?


$excelreader = new PHPExcel_Reader_Excel2007();
$loadexcel = $excelreader->load('uploads/excel/'.$data_upload['file_name']);


$excelreader = PHPExcel_IOFactory::load('uploads/excel/'.$data_upload['file_name']);

And before that lines do not forget to add


And taraa….

The complete example you can look at my code, I hope it can help us someday.

include APPPATH.'libraries/PHPExcel.php';
$data_upload = $this->upload->data();
$excelreader = PHPExcel_IOFactory::load('uploads/excel/'.$data_upload['file_name']);
$sheet = $excelreader->getActiveSheet()->toArray(null, true, true ,true);
$data = array();
$numrow = 1;
foreach($sheet as $row){
if($numrow > 1){
array_push($data, array(
//something to push

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments

Would love your thoughts, please comment.x