[英]PHP ZipArchive Issue
it's the first time I'm using PHP to make ZIP archives. 这是我第一次使用PHP制作ZIP存档。 However, I am not getting any zip files even though no error is being outputted.
但是,即使没有输出错误,我也没有得到任何zip文件。 I did
echo $zip->close
and it gave 1 . 我没有
echo $zip->close
,它给出了1 。
Can someone help me? 有人能帮我吗?
/* 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();
Maybe try this instead: 也许试试看:
<?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();
In the first argument of the addFile()
method, provide the full path of your file name, and in the second provide a directory/location of your file with in the archive and that should do the trick. 在
addFile()
方法的第一个参数中,提供文件名的完整路径,在第二个参数中,提供归档文件中文件的目录/位置,这应该可以解决问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.