我正在尝试根据我在这里找到的内容创建一个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)
所以我的问题确实是:
提前致谢.担
ZipArchive 显然默认情况下没有编译成 PHP。您需要使用“--with-zip=”选项重新编译它,或者只需通过 PECL 安装它。
这是解释不同方法的手册页:
http://www.php.net/manual/en/zip.installation.php
| 归档时间: |
|
| 查看次数: |
12061 次 |
| 最近记录: |