RarArchive::isSolid
RarArchive::__toString
RarArchive
PHP Manual

# RarArchive::open

# rar_open

(PECL rar >= 2.0.0)

RarArchive::open -- rar_open — Open RAR archive.

### Descrição

Object oriented style (method):

public static RarArchive RarArchive::open ( string `$filename` [, string `$password` ] )

Procedural style:

RarArchive rar_open ( string `$filename` [, string `$password` ] )

Open specified RAR archive and return RarArchive instance representing it.

> Nota: If opening a multi-volume archive, the path of the first volume should be passed as the first parameter. Otherwise, not all files will be shown. This is by design.

### Parâmetros

`filename`

  Path to the Rar archive.

`password`

  A plain password, if needed to decrypt the headers. It will also be used by default if encrypted files are found. Note that the files may have different passwords in respect to the headers and among them.

Aviso

Prior to version 2.0.0, this function would not handle relative paths correctly. Use realpath() as a workaround.

### Valor Retornado

Returns the requested RarArchive instance or `FALSE` on failure.

### Exemplos

Exemplo #1 Object oriented style

`<?php
$rar_arch = RarArchive::open('encrypted_headers.rar', 'samplepassword');
if ($rar_arch === FALSE)
die("Failed opening file");
$entries = $rar_arch->getEntries();
if ($entries === FALSE)
die("Failed fetching entries");
echo "Found " . count($entries) . " files.\n";
if (empty($entries))
die("No valid entries found.");
$stream = reset($entries)->getStream();
if ($stream === FALSE)
die("Failed opening first file");
$rar_arch->close();
echo "Content of first one follows:\n";
echo stream_get_contents($stream);
fclose($stream);
?>`

O exemplo acima irá imprimir algo similar a:

    Found 2 files.
    Content of first one follows:
    Encrypted file 1 contents.

Exemplo #2 Procedural style

`<?php
$rar_arch = rar_open('encrypted_headers.rar', 'samplepassword');
if ($rar_arch === FALSE)
die("Failed opening file");
$entries = rar_list($rar_arch);
if ($entries === FALSE)
die("Failed fetching entries");
echo "Found " . count($entries) . " files.\n";
if (empty($entries))
die("No valid entries found.");
$stream = reset($entries)->getStream();
if ($stream === FALSE)
die("Failed opening first file");
rar_close($rar_arch);
echo "Content of first one follows:\n";
echo stream_get_contents($stream);
fclose($stream);
?>`

RarArchive::isSolid
RarArchive::__toString
RarArchive
PHP Manual