Class' ZipArchive'在PHPExcel中找不到

时间:2017-08-19 00:16:02

标签: php excel phpexcel

我在名为" Collective Access"的程序中收到以下错误,但我不确定从哪里开始,因为我还没有遇到过此类问题的经验之前:

PHP Fatal error:  Uncaught Error: Class 'ZipArchive' not found in /var/www/html/providence/app/lib/core/Parsers/PHPExcel/PHPExcel/Reader/Excel2007.php:94
Stack trace:
#0 /var/www/html/providence/app/lib/core/Parsers/PHPExcel/PHPExcel/IOFactory.php(268): PHPExcel_Reader_Excel2007->canRead('project/mapping...')
#1 /var/www/html/providence/app/lib/core/Parsers/PHPExcel/PHPExcel/IOFactory.php(191): PHPExcel_IOFactory::createReaderForFile('project/mapping...')
#2 /var/www/html/providence/app/models/ca_data_importers.php(768): PHPExcel_IOFactory::load('project/mapping...')
#3 /var/www/html/providence/app/lib/ca/Utils/CLIUtils.php(1147): ca_data_importers::loadImporterFromFile('project/mapping...', Array, Array)
#4 /var/www/html/providence/support/bin/caUtils(166): CLIUtils::load_import_mapping(Object(Zend_Console_Getopt))
#5 {main}
  thrown in /var/www/html/providence/app/lib/core/Parsers/PHPExcel/PHPExcel/Reader/Excel2007.php on line 94

PS - 这是它所指的文件第94行的代码:

$xl = false;
    // Load file
    $zip = new $zipClass;
    if ($zip->open($pFilename) === true) {
        // check if it is an OOXML archive
        $rels = simplexml_load_string($this->_getFromZipArchive($zip, "_rels/.rels"), 'SimpleXMLElement', PHPExcel_Settings::getLibXmlLoaderOptions());
        if ($rels !== false) {
            foreach ($rels->Relationship as $rel) {
                switch ($rel["Type"]) {
                    case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument":
                        if (basename($rel["Target"]) == 'workbook.xml') {
                            $xl = true;
                        }
                        break;

                }
            }
        }
        $zip->close();
    }

    return $xl;
}

修改

我使用7.0.15-0ubuntu0.16.04.4 for php(或者只是Ubuntu Server 16.04.4上的7.0版)

1 个答案:

答案 0 :(得分:0)

ZipArchive类由Zip PHP extension提供,根据its documentation需要在PHP(在Linux上)或在php.ini(在...上)的编译中启用窗口)。

您的系统很可能无法使用该扩展程序。将<?php phpinfo();写入新文件,在浏览器中打开(通过网络服务器)并检查Zip扩展是否已编译或启用。

如果您的脚本是命令行工具,那么使用PHP CLI运行phpinfo()文件或只需在终端中运行:

$ php -m

查看已加载的扩展(模块)列表或

$ php -i

查看phpinfo()显示的完整信息。