$zip = new ZipArchive; if ($zip->open('example.zip', ZipArchive::CREATE) === TRUE) { $zip->addFile('path/to/file.txt', 'newname.txt'); $zip->close(); echo 'File added to ZIP archive'; } else { echo 'Error creating ZIP archive'; }In this example, we create a new ZipArchive object and open a new ZIP archive called 'example.zip'. Then we use the addFile method to add a file called 'file.txt' located in the 'path/to/' directory to the ZIP archive, but we rename it to 'newname.txt' in the archive. Finally, we close the ZIP archive and output a message indicating success or failure. Package library: PHP Standard Library (built-in to PHP)