- 官方自带操作类zip
private function addFileToZip($path,$new, $zip){
$handler = opendir($path);
while (($filename = readdir($handler)) !== false) {
if ($filename != "." && $filename != "..") {
if (is_dir($path . "/" . $filename)) {
$this->addFileToZip($path . "/" . $filename,$new, $zip);
} else {
$zip->addFile($path . "/" . $filename,$new . "/" . $filename);
}
}
}
}
$zip = new ZipArchive();
$zip->open(__DIR__."/$biaoshi.zip",ZipArchive::CREATE|ZipArchive::OVERWRITE);
$zip->addFile(__DIR__."/template/phoneapp/index.html","$biaoshi/template/phoneapp/index.html");//添加文件
$zip->addFile(__DIR__."/common/fn.php","$biaoshi/common/fn.php");
$zip->addFromString("$biaoshi/mod.ini", "test=测试\n [sex]\n 0=未知\n 1=男\n 2=女");//添加字符到文件
$this->addFileToZip(__DIR__."/common/weui","$biaoshi/common/weui", $zip);//添加目录
$zip->setArchiveComment("Auothor:Yoby\n Date:$now");//说明支持英文
$zip->close();
header("Content-type: application/octet-stream");
header("Content-disposition: attachment; filename=".$biaoshi.".zip");
@readfile(__DIR__."/".$biaoshi.".zip");
unlink(__DIR__."/".$biaoshi.".zip");
$zip->renameName('currentname.txt','newname.txt');//重命名
$zip->deleteName('testfromfile.php'); 删除文件,删除不了目录
$zip->extractTo("./ss/");解压
作者:Yoby 创建时间:2020-09-17 00:29
更新时间:2024-12-05 13:26
更新时间:2024-12-05 13:26