I couldn't find any how-to example for getting the filenames, so I made an easy one.
Here's an example how to list all filenames from a zip-archive:
<?php
$zip = new ZipArchive;
if ($zip->open('items.zip'))
{
for($i = 0; $i < $zip->numFiles; $i++)
{
echo 'Filename: ' . $zip->getNameIndex($i) . '<br />';
}
}
else
{
echo 'Error reading zip-archive!';
}
?>
Hope it helps.
ZipArchive::getNameIndex
(PHP 5 >= 5.2.0, PECL zip >= 1.5.0)
ZipArchive::getNameIndex — インデックスを使用して、エントリの名前を返す
説明
string ZipArchive::getNameIndex
( int
$index
[, int $flags
] )インデックスを使用して、エントリの名前を返します。
パラメータ
-
index -
エントリのインデックス。
-
flags -
ZIPARCHIVE::FL_UNCHANGEDを指定すると、 元の変化していないコメントを返します。
返り値
成功した場合に名前、失敗した場合に FALSE を返します。
例
例1 getnameindex() の例
<?php
if ($zip->open('test.zip') == TRUE) {
for ($i = 0; $i < $zip->numFiles; $i++) {
$filename = $zip->getNameIndex($i);
// ...
}
}
?>
Yeslifer ¶
4 years ago
