<?php
$zip = new ZipArchive();
$filename = "/tmp/test112.zip";
if ($zip->open($filename, ZIPARCHIVE::CREATE)!==TRUE) {
exit("cannot open <$filename>\n");
}
$basePath='/tmp/test';
if ($dh = opendir($basePath)){
while (($file = readdir($dh)) !== false){
if($file!='.' && $file!='..'){
$zip->addFile( $basePath.'/'.$file);
}
}
}
$zip->addFromString("testfilephp.txt","#1 This is a test string added as testfilephp.txt.\n");
$zip->addFromString("testfilephp2.txt","#2 This is a test string added as testfilephp2.txt.\n");
$zip->addFile( "/tmp/test/t.php");
echo "numfiles: " . $zip->numFiles . "\n";
echo "status:" . $zip->status . "\n";
$zip->close();这里只是遍历了一层文件目录
版权声明:本文为oZhengTuoJiaSuo原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。