RarArchive::getEntries
rar_list
(PECL rar >= 2.0.0)
RarArchive::getEntries -- rar_list — Get full list of entries from the RAR archive
Description
Object oriented style (method):
Procedural style:
Get entries list (files and directories) from the RAR archive.
Note:
If the archive has entries with the same name, this method, together with RarArchive foreach iteration and array-like access with numeric indexes, are the only ones to access all the entries (i.e., RarArchive::getEntry() and the rar:// wrapper are insufficient).
Return Values
rar_list() returns array of RarEntry objects
or FALSE
on failure.
Changelog
Version | Description |
---|---|
3.0.0 | Support for RAR archives with repeated entry names is no longer defective. |
Examples
Example #1 Object oriented style
<?php
$rar_arch = RarArchive::open('solid.rar');
if ($rar_arch === FALSE)
die("Could not open RAR archive.");
$rar_entries = $rar_arch->getEntries();
if ($rar_entries === FALSE)
die("Could retrieve entries.");
echo "Found " . count($rar_entries) . " entries.\n";
foreach ($rar_entries as $e) {
echo $e;
echo "\n";
}
$rar_arch->close();
?>
The above example will output something similar to:
Found 2 entries. RarEntry for file "tese.txt" (23b93a7a) RarEntry for file "unrardll.txt" (2ed64b6e)
Example #2 Procedural style
<?php
$rar_arch = rar_open('solid.rar');
if ($rar_arch === FALSE)
die("Could not open RAR archive.");
$rar_entries = rar_list($rar_arch);
if ($rar_entries === FALSE)
die("Could retrieve entries.");
echo "Found " . count($rar_entries) . " entries.\n";
foreach ($rar_entries as $e) {
echo $e;
echo "\n";
}
rar_close($rar_arch);
?>
- PHP Руководство
- Функции по категориям
- Индекс функций
- Справочник функций
- Расширения для сжатия и архивации
- Архивирование Rar
- Функция RarArchive::close() - Закрывает RAR архив и освобождает все ресурсы
- Функция RarArchive::getComment() - Get comment text from the RAR archive
- Функция RarArchive::getEntries() - Возвращает полный список элемнтов из RAR архива
- Функция RarArchive::getEntry() - Возвращает объект элемента из RAR архива
- Функция RarArchive::isBroken() - Test whether an archive is broken (incomplete)
- Функция RarArchive::isSolid() - Check whether the RAR archive is solid
- Функция RarArchive::open() - Открывает RAR архив
- Функция RarArchive::setAllowBroken() - Whether opening broken archives is allowed
- Функция RarArchive::__toString() - Get text representation
Коментарии
Can be usefult for many, probably:
<?php
$path = 'path/to/archive';
$archive = RarArchive::open($path);
$list = $archive ->getEntries();
foreach ($list as $entity) {
//print just title of file from archive(use getters to access other fields, etc)
echo $value->getName();
}
?>
at the examples line 7 should be:
die("Could NOT retrieve entries.");