ZipArchive - List files in the archive

Hi,

I’m trying to get a list of the files contained in a zip archive, and it is not immediately apparent how to do this. I can see the values of the [name] element with:
[php]
$zip = new ZipArchive();
$file = ‘/some/file.zip’;
$zip->open($file);
$numfiles = $zip->numFiles;
print_r($zip->statIndex($i));
[/php]
…but I’m not interested in dumping the raw array out; only accessing the [name] element. I had thought that this would be done with [php]$foo = $zip->statIndex($i)[name];[/php] or [php]$foo = $zip->statIndex($i)[‘name’];[/php] but PHP just complains about an unexpected ‘[’.
Can anyone nudge me in the right direction?
Thanks,
A

Since this is a function call, you can not just append index to this expression to access array element. But, since this function returns an array, you can do the following:

[php]$arr = $zip->statIndex($i);
$foo = $arr[‘name’];
[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service