PHP Zip创建类ZipArchive未找到错误

Dan*_*ing 5 php zip zlib

我正在尝试根据我在这里找到的内容创建一个zip脚本,但我似乎遇到致命错误:在新的ZipArchive()上找不到类'ZipArchive'错误; 功能.

研究这似乎通常是由于PHP的编译方式.我有一个共享主机帐户,所以我没有配置任何这些东西......我认为我不能对构建进行任何更改.出于兴趣,我看了一下我的phpinfo(),我找到了一些看似相关的东西:

PHP版本5.2.6

BZip2 Support   Enabled    <--maybe not so relevant
ZLib Support    enabled
Stream Wrapper support  compress.zlib://
Stream Filter support   zlib.inflate, zlib.deflate
Compiled Version    1.1.4
Linked Version  1.1.4 
Run Code Online (Sandbox Code Playgroud)

我并不十分确定这是否意味着我有能力创建拉链.有关更多信息(虽然我不认为它是重温的)这里是我的脚本到目前为止....这是未经考验的头脑你,因为我无法得到这个类未找到错误.

$file = tempnam("tmp", "zip");
$zip = new ZipArchive();
$zip->open($file, ZipArchive::OVERWRITE);


   //the string "file1" is the name we're assigning the file in the archive
$zip->addFile('show1.jpg', 'file1.jpg');
$zip->addFile('show2.jpg', 'file2.jpg');
$zip->addFile('show3.jpg', 'file3.jpg');
$zip->addFile('show4.jpg', 'file4.jpg');
$zip->addFile('show5.jpg', 'file5.jpg');
$zip->addFile('show6.jpg', 'file6.jpg');

// echo $zip->file(); //this sends the compressed archive to the output buffer instead of writing it to a file.

$zip->close();
header('Content-Type: application/zip');
header('Content-Length: ' . filesize($file));
header('Content-Disposition: attachment; filename="' . $file.'"');
readfile($file);
unlink($file); 
Run Code Online (Sandbox Code Playgroud)

所以我的问题确实是:

  1. 我在脚本中做了什么导致此错误?
  2. 我的phpinfo()中的任何东西是否意味着我应该能够创建zip文件,如果我不应该在那里寻找什么,如果我有能力将让我知道.
  3. 看起来这个ZLib是一些软库,但我不知道它是否做了我想做的事情,甚至如何使用它....这有点像预感,但如果它可以帮助我创建zip文件可以让任何人指出我正确的方向如何使用它?

提前致谢.担

vic*_*LLA 3

ZipArchive 显然默认情况下没有编译成 PHP。您需要使用“--with-zip=”选项重新编译它,或者只需通过 PECL 安装它。

这是解释不同方法的手册页:

http://www.php.net/manual/en/zip.installation.php

  • 如果您的托管提供商不会使用 zip 重做 PHP 构建,那么 PCLZip 库可能是替代方案 (4认同)
  • 我认为虽然我使用的是共享托管帐户,但我不能这样做吗?网络托管提供商(在我的例子中是streamline.net)是唯一可以重新编译php/添加内容的提供商?...或者我可以做些什么? (2认同)