<?php $zip = new ZipArchive; $myfile = fopen("test.zip", "w"); chmod("test.zip",0777); if ($zip->open('test.zip') === TRUE) { $zip->addFile('/Library/WebServer/Documents/ibarn/data/01/20190728/17d5942b1b9b2515b883d5d0ea60f34a.xlsx', '17d5942b1b9b2515b883d5d0ea60f34a.xlsx'); $zip->close(); echo 'ok'; } else { echo 'failed'; } ?>
输出
ok
参考:
https://www.php.net/manual/en/ziparchive.addfile.php
https://blog.csdn.net/qq_38794041/article/details/81483739