(PECL rar >= 3.0.0)
RarArchive::setAllowBroken — Whether opening broken archives is allowed
面向对象风格 (method):
$allow_broken
): bool过程化风格:
This method defines whether broken archives can be read or all the operations that attempt to extract the archive entries will fail. Broken archives are archives for which no error is detected when the file is opened but an error occurs when reading the entries.
rarfile
A RarArchive object, opened with rar_open().
allow_broken
Whether to allow reading broken files (true
) or not (false
).
Returns true
或者在失败时返回 false
. It will only fail if the file has
already been closed.
示例 #1 面向对象风格
<?php
function retnull() { return null; }
$file = dirname(__FILE__) . "/multi_broken.part1.rar";
/* Third argument omits "volume not found" message */
$a = RarArchive::open($file, null, 'retnull');
$a->setAllowBroken(true);
foreach ($a->getEntries() as $e) {
echo "$e\n";
}
var_dump(count($a));
?>
以上例程的输出类似于:
RarEntry for file "file1.txt" (52b28202) int(1)
示例 #2 过程化风格
<?php
function retnull() { return null; }
$file = dirname(__FILE__) . "/multi_broken.part1.rar";
/* Third argument omits "volume not found" message */
$a = rar_open($file, null, 'retnull');
rar_allow_broken_set($a, true);
foreach (rar_list($a) as $e) {
echo "$e\n";
}
var_dump(count($a));
?>