W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
(PECL rar >= 2.0.0)
RarArchive::open -- rar_open — 打開 RAR 存檔
面向?qū)ο箫L格 (method):
public static RarArchive::open(string $filename, string $password = NULL, callable $volume_callback = NULL): RarArchive|false
過程化風格:
rar_open(string $filename, string $password = NULL, callable $volume_callback = NULL): RarArchive|false
打開指定的 RAR 存檔并返回表示它的 RarArchive 實例。
注意:如果打開多卷歸檔文件,則應(yīng)將第一個卷的路徑作為第一個參數(shù)傳遞。 否則,不會顯示所有文件。這是設(shè)計使然。
filename
Rar 存檔的路徑。
password
一個普通的密碼,如果需要解密標頭。默認情況下也會使用它 如果找到加密文件。請注意,這些文件可能具有 關(guān)于標頭和標頭之間的不同密碼。
volume_callback
接收一個參數(shù)的函數(shù) – 卷的路徑 未找到 – 并返回具有正確路徑的字符串 對于此類卷,如果此類卷為 null,則為 null
不存在或未知。程序員應(yīng)確保 傳遞的函數(shù)不會導致循環(huán),因為此函數(shù)被調(diào)用 如果上一個調(diào)用中返回的路徑未返回,則重復 對應(yīng)于所需的體積。指定此參數(shù)將省略 每當卷 未找到;因此,僅返回 null
的實現(xiàn)可用于省略此類通知。
警告
在版本 2.0.0 之前,此函數(shù)不會處理相對 正確的路徑。使用 realpath() 作為解決方法。
Returns the requested RarArchive instance 或者在失敗時返回 false.
版本 | 說明 |
---|---|
PECL rar 3.0.0 | volume_callback 被添加。 |
示例 #1 面向?qū)ο箫L格
<?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");
?>
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: