ZipArchive是PHP中操作ZIP压缩文件的类。它提供了创建、打开、读取、添加、更新、删除和解压缩ZIP文件的功能。
以下是ZipArchive的常见用法示例:
$zip = new ZipArchive(); $zip->open('path/to/archive.zip', ZipArchive::CREATE); $zip->close(); $zip = new ZipArchive(); $zip->open('path/to/archive.zip'); $zip->addFile('path/to/file.txt', 'file.txt'); $zip->addEmptyDir('path/to/directory'); $zip->addGlob('path/to/directory/*'); $zip->extractTo('path/to/destination'); $fileList = []; for ($i = 0; $i < $zip->numFiles; $i++) { $fileList[] = $zip->getNameIndex($i); } $zip->deleteName('file.txt'); $zip->close(); 这些只是ZipArchive类的一些常见用法示例,还有其他更多的方法可供使用。具体使用方法可以参考PHP官方文档中的ZipArchive类文档:https://www.php.net/manual/en/class.ziparchive.php