这是我第一次使用PHP来创建ZIP文档。但是,即使没有输出错误,我也不会得到任何压缩文件。我做了echo $zip->close,它给了1。
有人能帮我吗?
/* Create zip folder */
$zip = new ZipArchive();
$zipCreate = $zip->open("newarchive.zip", ZipArchive::CREATE);
if($zipCreate !== TRUE) {
die("Zip folder creation failed");
}
$zip->addFile("test.txt", "test.txt");
$zip->addFile("helllo.txt", "helllo.txt");
$zip->close();发布于 2014-11-23 11:37:23
不妨试一试:
<?php
/* Create zip folder */
$zip = new ZipArchive();
$zipCreate = $zip->open("newarchive.zip", ZipArchive::CREATE);
if($zipCreate !== TRUE) {
die("Zip folder creation failed");
}
$directory = getcwd() . '/';
$files = array('test.txt', 'helllo.txt');
foreach($files as $file) {
$zip->addFile($directory . $file, basename($file));
}
$zip->close();在addFile()方法的第一个参数中,提供文件名的完整路径,在第二个参数中,在归档中提供文件的目录/位置,这将起到很好的作用。
https://stackoverflow.com/questions/27088378
复制相似问题