https://www.php.cn/faq/415187.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
| $zip = new ZipArchive;
$zipname = $path . '/' . $uploadid . date('__Ymd_His') . '.zip';
if ($zip->open($zipname, ZipArchive::CREATE) === false) {
die('zip 压缩失败');
}
$fname = "f.docx";
$filename = "{$path}/{$fname}";
$zip->addFile($filename, $fname);
$zip->addFromString('ff/f.txt', '要添加到new.txt文件中的文本');
$zip->close();
|