ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
rar://—RAR **注意**:**默认情况下未启用此包装器。** 要使用rar://包装器,必须安装[»PECL中](https://pecl.php.net/)的[»rar](https://pecl.php.net/package/rar)扩展名。 **包装摘要** | 属性 | 支持的 | | --- | --- | | 受[allow\_url\_fopen](https://www.php.net/manual/en/filesystem.configuration.php#ini.allow-url-fopen)限制[](https://www.php.net/manual/en/filesystem.configuration.php#ini.allow-url-fopen) | 没有 | | 受[allow\_url\_include](https://www.php.net/manual/en/filesystem.configuration.php#ini.allow-url-include)限制[](https://www.php.net/manual/en/filesystem.configuration.php#ini.allow-url-include) | 没有 | | 允许阅读 | 是 | | 允许写作 | 没有 | | 允许追加 | 没有 | | 允许同时读写 | 没有 | | 支持[stat()](https://www.php.net/manual/en/function.stat.php) | 是 | | 支持[unlink()](https://www.php.net/manual/en/function.unlink.php) | 没有 | | 支持[rename()](https://www.php.net/manual/en/function.rename.php) | 没有 | | 支持[mkdir()](https://www.php.net/manual/en/function.mkdir.php) | 没有 | | 支持[rmdir()](https://www.php.net/manual/en/function.rmdir.php) | 没有 | **上下文选项** | 名称 | 用法 | 默认 | | --- | --- | --- | | *open\_password* | 用于加密档案标题的密码(如果有)。当出现更高版本的文件时,WinRAR将使用与标题密码相同的密码来加密所有文件,因此对于具有加密标题的档案,*file\_password*将被忽略。 |   | | *file\_password* | 用于加密文件的密码(如果有)。如果标头也已加密,则此选项将被*open\_password*忽略。之所以有两个选择,是为了解决在出现这些档案时支持具有不同标题和文件密码的档案的可能性。请注意,如果归档文件的标题未加密,则*open\_password*将被忽略,而必须使用此选项。 |   | | *volume\_callback* | 确定丢失卷路径的回调。有关更多信息,请参见[RarArchive :: open()](https://www.php.net/manual/en/rararchive.open.php)。 | **遍历RAR文件** ``` class MyRecDirIt extends RecursiveDirectoryIterator { function current() { return rawurldecode($this->getSubPathName()) . (is_dir(parent::current())?" [DIR]":""); } } $f = "rar://" . rawurlencode(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'dirs_and_extra_headers.rar#'; $it = new RecursiveTreeIterator(new MyRecDirIt($f)); foreach ($it as $s) { echo $s, "\n"; } ``` **打开一个加密的文件(头加密)** ``` $stream = fopen("rar://" . rawurlencode(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'encrypted_headers.rar' . '#encfile1.txt', "r", false, stream_context_create( array( 'rar' => array( 'open_password' => 'samplepassword' ) ) ) ); var_dump(stream_get_contents($stream)); /* creation and last access date is opt-in in WinRAR, hence most * files don't have them */ var_dump(fstat($stream)); ```