No cache version.

Caching disabled. Default setting for this page:enabled (code LNG204)
If the display is too slow, you can disable the user mode to view the cached version.

Rechercher une fonction PHP

RarArchive::open

rar_open

(PECL rar >= 2.0.0)

RarArchive::open -- rar_openOpen RAR archive

PHP: RarArchive::open - Manual Home of Manuel PHP  Contents Haut

Description

Object oriented style (method):

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

Procedural style:

rar_open ( string $filename [, string $password = NULL [, callable $volume_callback = NULL ]] ) : RarArchive

Open specified RAR archive and return RarArchive instance representing it.

Note:

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.

PHP: RarArchive::open - Manual Home of Manuel PHP  Contents Haut

Parameters

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.

Warning

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

PHP: RarArchive::open - Manual Home of Manuel PHP  Contents Haut

Return Values

Returns the requested RarArchive instance or FALSE on failure.

PHP: RarArchive::open - Manual Home of Manuel PHP  Contents Haut

Changelog

Version Description
3.0.0 volume_callback was added.

PHP: RarArchive::open - Manual Home of Manuel PHP  Contents Haut

Examples

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

The above example will output something similar to:

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

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

Example #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");
?>

Find a PHP function

English translation

You have asked to visit this site in English. For now, only the interface is translated, but not all the content yet.

If you want to help me in translations, your contribution is welcome. All you need to do is register on the site, and send me a message asking me to add you to the group of translators, which will give you the opportunity to translate the pages you want. A link at the bottom of each translated page indicates that you are the translator, and has a link to your profile.

Thank you in advance.

Document created the 30/01/2003, last modified the 26/10/2018
Source of the printed document:https://www.gaudry.be/en/php-rf-rararchive.open.html

The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.

References

  1. View the html document Language of the document:fr Manuel PHP : http://php.net

These references and links indicate documents consulted during the writing of this page, or which may provide additional information, but the authors of these sources can not be held responsible for the content of this page.
The author This site is solely responsible for the way in which the various concepts, and the freedoms that are taken with the reference works, are presented here. Remember that you must cross multiple source information to reduce the risk of errors.

Contents Haut