open($file, ZipArchive::CREATE) !== true) throw new RuntimeException("Cannot create archive"); $zip->addFromString("notes/readme.txt", "Return tools clean"); $zip->close(); if ($zip->open($file) !== true) throw new RuntimeException("Cannot reopen archive"); try { echo $zip->getFromName("notes/readme.txt"), "\n"; } finally { $zip->close(); } } finally { if (is_file($file)) unlink($file); }