RarArchive::open

rar_open

(PECL rar >= 2.0.0)

RarArchive::open - rar_open - RAR 아카이브 열기


설명

Object-oriented style (method):

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

Procedural style:

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

지정된 RAR 아카이브를 열고 이를 나타내는 RarArchive 인스턴스를 반환합니다.

메모: 다중 볼륨 아카이브를 여는 경우 첫 번째 볼륨의 경로를 첫 번째 매개변수로 전달해야 합니다. 그렇지 않으면 모든 파일이 표시되지 않습니다. 이것은 의도적으로 설계된 것입니다.


매개변수

filename
Rar 아카이브 경로.
password
헤더를 해독하는 데 필요한 경우 일반 암호입니다. 암호화된 파일이 발견된 경우에도 기본적으로 사용됩니다. 파일은 헤더 및 헤더와 관련하여 다른 암호를 가질 수 있습니다.
volume_callback
하나의 매개변수(발견되지 않은 볼륨의 경로)를 수신하고 해당 볼륨에 대한 올바른 경로가 있는 문자열을 반환하거나 해당 볼륨이 존재하지 않거나 알 수 없는 경우 null을 반환하는 함수입니다. 프로그래머는 이전 호출에서 반환된 경로가 필요한 볼륨과 일치하지 않는 경우 이 함수가 반복적으로 호출되기 때문에 전달된 함수가 루프를 일으키지 않도록 해야 합니다. 이 매개변수를 지정하면 볼륨을 찾을 수 없을 때마다 내보내는 알림이 생략됩니다. 따라서 null만 반환하는 구현은 이러한 알림을 단순히 생략하는 데 사용할 수 있습니다.

경고 버전 2.0.0 이전에는 이 함수가 상대 경로를 올바르게 처리하지 못했습니다. 해결 방법으로 realpath()를 사용하십시오.


반환 값

요청된 RarArchive 인스턴스를 반환하거나 실패 시 false를 반환합니다.


변경 로그

버전 설명
PECL rar 3.0.0 volume_callback이 추가되었습니다.

Examples

예제 #1 객체 지향 스타일

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

위의 예는 다음과 유사한 결과를 출력합니다.

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

예제 #2 절차 스타일

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

예제 #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(null, dirname(__FILE__) . "/temp_file2.txt");
?>
                  
                

기타