我正在尝试创建一个基于我在这里找到的内容的zip脚本,但是当我使用new ZipArchive()函数时出现了致命错误:Class 'ZipArchive' not found。
我的问题真正是:
研究后发现,这通常是由于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
我不确定这是否意味着我有创建zip文件的能力。以下是我的脚本,提供更多信息(尽管我认为这并不相关)。需要说明的是,由于我无法通过“类未找到”错误,因此此脚本未经过测试。
$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);
我的问题真正是:
- 我在脚本中做了什么导致了这个错误?
- 我的phpinfo()中的任何内容是否意味着我应该能够创建zip文件,如果不是,那我应该在其中寻找什么来知道我是否具备这个功能。
- 看起来这个ZLib是某种库,但我不知道它是否能做我想要的事情,甚至如何使用它...这是一个猜想,但如果它可以帮助我创建zip文件,有人能指引我如何使用它吗?