$zip = new ZipArchive; $res = $zip->open('example.zip'); if ($res === TRUE) { $index = 0; // index of the file echo $zip->getNameIndex($index); // returns the filename of the file at index 0 $zip->close(); } else { echo 'Failed to open the archive'; }
$zip = new ZipArchive; $res = $zip->open('example.zip'); if ($res === TRUE) { $index = 2; // index of the file echo $zip->getNameIndex($index); // returns the filename of the file at index 2 $zip->close(); } else { echo 'Failed to open the archive'; }In these two examples, we open a ZIP archive using the ZipArchive class and then use the getNameIndex() method to return the filename of a file at a specific index. Based on the use of the ZipArchive class, it is safe to assume that this code is being used in a PHP environment and that the package library being used is likely part of the PHP standard library.