CakeFest 2024: The Official CakePHP Conference

RarArchive::getEntries

rar_list

(PECL rar >= 2.0.0)

RarArchive::getEntries -- rar_listGet full list of entries from the RAR archive

Descrição

Estilo orientado a objetos (method):

public RarArchive::getEntries(): array|false

Estilo procedural:

rar_list(RarArchive $rarfile): array|false

Get entries list (files and directories) from the RAR archive.

Nota:

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).

Parâmetros

rarfile

A RarArchive object, opened with rar_open().

Valor Retornado

rar_list() returns array of RarEntry objects ou false em caso de falha.

Registro de Alterações

Versão Descrição
PECL rar 3.0.0 Support for RAR archives with repeated entry names is no longer defective.

Exemplos

Exemplo #1 Estilo orientado a objetos

<?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 not retrieve entries.");

echo
"Found " . count($rar_entries) . " entries.\n";

foreach (
$rar_entries as $e) {
echo
$e;
echo
"\n";
}
$rar_arch->close();
?>

O exemplo acima produzirá algo semelhante a:

Found 2 entries.
RarEntry for file "tese.txt" (23b93a7a)
RarEntry for file "unrardll.txt" (2ed64b6e)

Exemplo #2 Estilo procedural

<?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);
?>

Veja Também

add a note

User Contributed Notes 2 notes

up
2
Anonymous
9 years ago
at the examples line 7 should be:
die("Could NOT retrieve entries.");
up
1
grap at hot dot ee
11 years ago
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();
}
?>
To Top