RarArchive::open

rar_open

(PECL rar >= 2.0.0)

RarArchive::open -- rar_openOpen RAR archive

Beschreibung

Objektorientierter Stil (method):

public static RarArchive::open(string $filename, string $password = NULL, callable $volume_callback = NULL): RarArchive|false

Prozeduraler Stil:

rar_open(string $filename, string $password = NULL, callable $volume_callback = NULL): RarArchive|false

Open specified RAR archive and return RarArchive instance representing it.

Hinweis:

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.

Parameter-Liste

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.

volume_callback

A function that receives one parameter – the path of the volume that was not found – and returns a string with the correct path for such volume or null if such volume does not exist or is not known. The programmer should ensure the passed function doesn't cause loops as this function is called repeatedly if the path returned in a previous call did not correspond to the needed volume. Specifying this parameter omits the notice that would otherwise be emitted whenever a volume is not found; an implementation that only returns null can therefore be used to merely omit such notices.

Warnung

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

Rückgabewerte

Returns the requested RarArchive instance Bei einem Fehler wird false zurückgegeben..

Changelog

Version Beschreibung
PECL rar 3.0.0 volume_callback was added.

Beispiele

Beispiel #1 Objektorientierter Stil

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

Das oben gezeigte Beispiel erzeugt eine ähnliche Ausgabe wie:

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

Beispiel #2 Prozeduraler Stil

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

Beispiel #3 Volume Callback

<?php
/* In this example, there's a volume named multi_broken.part1.rar
 * whose next volume is named multi.part2.rar */
function resolve($vol) {
    if (
preg_match('/_broken/'$vol))
        return 
str_replace('_broken'''$vol);
    else
        return 
null;
}
$rar_file1 rar_open(dirname(__FILE__).'/multi_broken.part1.rar'null'resolve');
$entry $rar_file1->getEntry('file2.txt');
$entry->extract(nulldirname(__FILE__) . "/temp_file2.txt");
?>

Siehe auch

Hier Kannst Du einen Kommentar verfassen


Bitte gib mindestens 10 Zeichen ein.
Wird geladen... Bitte warte.
* Pflichtangabe
Es sind noch keine Kommentare vorhanden.

Grundlagen von Views in MySQL

Views in einer MySQL-Datenbank bieten die Möglichkeit, eine virtuelle Tabelle basierend auf dem Ergebnis einer SQL-Abfrage zu erstellen. ...

admin

Autor : admin
Kategorie: mySQL-Tutorials

Definition von Stored Procedures - eine Einführung

Stored Procedures sind vordefinierte SQL-Codeblöcke, die in einer Datenbank gespeichert sind und bei Bedarf aufgerufen werden können. ...

Bernie

Autor : ebiz-consult GmbH & Co. KG
Kategorie: mySQL-Tutorials

Wie kann man komplexe Abfragen mit SQL-Querys In MySQLi effektiv durchführen?

In diesem MySQL-Tutorial wird erklärt, wie komplexe SQL-Abfragen in MySQLi effizient durchgeführt werden können. Wir werden uns mit verschiedenen Aspekten der Datenbankabfrage beschäftigen und spezifische Methoden kennenlernen. ...

TheMax

Autor : TheMax
Kategorie: mySQL-Tutorials

Tutorial veröffentlichen

Tutorial veröffentlichen

Teile Dein Wissen mit anderen Entwicklern weltweit

Du bist Profi in deinem Bereich und möchtest dein Wissen teilen, dann melde dich jetzt an und teile es mit unserer PHP-Community

mehr erfahren

Tutorial veröffentlichen

[Wichtig] Anmeldung im Forum

Guess the hidden word using logic and deduction in the engaging game of Wordle. Wordle nyt (https://wordlenytimes.net/) ​

Geschrieben von lenytimes am 19.04.2024 19:21:45
Forum: Fragen/Vorschläge zum Forum
Professioneller Webentwickler & Webdesigner

Of course, here is the translation: Hello, Thank you for your interest in the long-term project. Your extensive skills and experience in web dev ...

Geschrieben von Athelstan am 15.04.2024 09:25:39
Forum: Jobgesuche
Wir stellen unsere SEO-Agentur vor

Hallo In der heutigen digitalen Welt war es für Unternehmen noch nie so einfach, ihre Reichweite weltweit zu vergrößern. Wenn Sie außerhalb I ...

Geschrieben von thomasmuller am 14.04.2024 07:18:33
Forum: User stellen sich vor
Spielplan für 4 Gruppen zu je 6 Teams auf 2 Feldern

Hallöchen zusammen, ich versuche derzeit unseren Excel-Spielplan in PHP zu überführen. Eigentlich bin ich auch shon fertig - wenn da nicht dies ...

Geschrieben von derH0st am 11.04.2024 15:58:37
Forum: PHP Developer Forum