$zip = new ZipArchive; if ($zip->open('archive.zip') === TRUE) { $index = $zip->locateName('file.txt'); if ($index !== false) { $zip->extractTo('/destination/path', $index); } $zip->close(); }
$zip = new ZipArchive; if ($zip->open('archive.zip') === TRUE) { $index = $zip->locateName('file.txt'); if ($index !== false) { $zip->deleteIndex($index); } $zip->close(); }This code opens the archive.zip file and locates an entry called file.txt. If the entry is found, its index is stored in the $index variable, and the ZipArchive object deletes it from the archive. The locateName method belongs to the PHP ZipArchive package library, which provides a convenient way to create, manipulate, and extract ZIP archives in PHP.