[英]php zip archive
I tried to create empty/not empty zip archive. 我试图创建空/非空的zip存档。
Code used is below. 使用的代码如下。
Result: nothing happened. 结果:什么都没发生。
No errors, but also no results. 没有错误,也没有结果。
Any explanation appreciated. 任何解释表示赞赏。
$zip = new ZipArchive(); $zip->open('/home/admin/domains/domain.com/public_html/xxx_zip.zip', ZIPARCHIVE::CREATE); $zip->addFile('/home/admin/domains/domain.com/public_html/xxxxxx.css'); #$zip->addEmptyDir('.'); //also tried $zip->close();
available
可得到
Zip enabled启用拉链
Extension Version $Id: php_zip.c,v 1.1.2.50 2009/03/01 17:35:25 iliaa Exp $扩展版本$ Id:php_zip.c,v 1.1.2.50 2009/03/01 17:35:25 iliaa Exp $
Zip version 1.8.11邮编1.8.11
Libzip version 0.9.0Libzip 0.9.0版
The ZipArchive methods indicate failure by returning false. ZipArchive方法通过返回false来指示失败。 Did you check that?
你检查了吗? Did you check getStatusString ?
您检查过getStatusString吗?
check out other examples but this is how I got it working: 查看其他示例,但这是我如何使其工作的方式:
<?php
$dirArray = array();
/* creates a compressed zip file */
$zip = new ZipArchive;
if ($zip->open('dataminefiles.zip', ZIPARCHIVE::CREATE) !== TRUE) {
die ("Could not open archive");
}
// open the current dir
if ($handle = opendir('.')) {
while (false !== ($entry = readdir($handle))) {
// ignore hidden files
if ($entry != "." && $entry != "..") {
// only zip specific files
if ( substr($entry,-3,3) == "jpg" || substr($entry,-3,3) == "pdf" || substr($entry,-3,3) == "lsx" || substr($entry,-3,3) == "xls" || substr($entry,-3,3) == "doc" || substr($entry,-3,3) == "txt" || substr($entry,-3,3) == "png" || substr($entry,-3,3) == "gif" || substr($entry,-3,3) == "peg" ) {
// if allowed, add them to the array
$dirArray[] = $entry;
}
}
}
closedir($handle);
}
$indexCount = count($dirArray);
sort($dirArray);
// loop through the files and add them to the zip file
for($index=0; $index < $indexCount; $index++) {
$file = "{$dirArray[$index]}";
$zip->addFile($file, $file);
}
// close the zip file
$zip->close();
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.