手机版

PHP支持的协议和封装协议:rar://

2019-09-07 阅读 :

rar://RAR

说明

The wrapper takes the url encoded path to the RAR archive (relative or absolute), an optional asterik (*), an optional number sign (#) and an optional url encoded entry name, as stored in the archive. Specifying an entry name requires the number sign; a leading forward slash in the entry name is optional.

This wrapper can open both files and directories. When opening directories, the asterisk sign forces the directory entries names to be returned unencoded. If it's not specified, they will be returned url encoded – the reason for this is to allow the wrapper to be correctly used with built-in functionality like the RecursiveDirectoryIterator in the presence of file names that seem like url encoded data.

If the pound sign and the entry name part are not included, the root of the archive will be displayed. This differs from regular directories in that the resulting stream will not contain information such as the modification time, as the root directory is not stored in an individual entry in the archive. The usage of the wrapper with RecursiveDirectoryIterator requires the number sign to be included in the URL when accessing the root, so that the URLs of the children may be constructed correctly.

Note: This wrapper is not enabled by default
In order to use the rar:// wrapper, you must install the » rar extension available from » PECL.

rar:// Available since PECL rar 3.0.0

用法

  • rar://<url encoded archive name>[*][#[<url encoded entry name>]]

可选项

Wrapper Summary
Attribute Supported
Restricted by allow_url_fopen No
Restricted by allow_url_include No
Allows Reading Yes
Allows Writing No
Allows Appending No
Allows Simultaneous Reading and Writing No
Supports stat() Yes
Supports unlink() No
Supports rename() No
Supports mkdir() No
Supports rmdir() No

Context options
Name Usage Default
open_password The password used to encrypt the headers of the archive, if any. WinRAR will encrypt all the files with the same password as the headers password when the later is present, so for archives with encrypted headers, file_password will be ignored.  
file_password The password used to encrypt a file, if any. If the headers are also encrypted, this option will be ignored in favor of open_password. The reason there are two options is to cover the possibility of supporting archives with different headers and file passwords, should those archives arise. Note that if the archive does not have its headers encrypted, open_password will be ignored and this option must be used instead.  
volume_callback A callback to determine the path of missing volumes. See RarArchive::open() for more information.  

范例

Example #1 Traversing a RAR archive


<?php

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";
}
?>

以上例程的输出类似于:

|-allow_everyone_ni [DIR]|-file1.txt|-file2_אּ.txt|-with_streams.txt/-אּ [DIR]  |-אּ/%2Fempty%2E [DIR]  | /-אּ/%2Fempty%2E/file7.txt  |-אּ/empty [DIR]  |-אּ/file3.txt  |-אּ/file4_אּ.txt  /-אּ/אּ_2 [DIR]    |-אּ/אּ_2/file5.txt    /-אּ/אּ_2/file6_אּ.txt

Example #2 Opening an encrypted file (header encryption)


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

以上例程的输出类似于:

string(26) "Encrypted file 1 contents."Array(    [0] => 0    [1] => 0    [2] => 33206    [3] => 1    [4] => 0    [5] => 0    [6] => 0    [7] => 26    [8] => 0    [9] => 1259550052    [10] => 0    [11] => -1    [12] => -1    [dev] => 0    [ino] => 0    [mode] => 33206    [nlink] => 1    [uid] => 0    [gid] => 0    [rdev] => 0    [size] => 26    [atime] => 0    [mtime] => 1259550052    [ctime] => 0    [blksize] => -1    [blocks] => -1)
服务器教程 服务器知识 服务器技术 服务器之家 vps教程 vps是什么
本文标题:PHP支持的协议和封装协议:rar:// - 服务器教程_服务器技术_服务器知识_vps教程
本文地址:https://www.helloaliyun.com/tutorial/359.html

相关文章

  • CentOS 7 常用命令(系统关机、重启以及登出)

    关机:(系统的关机、重启以及登出 ) # 关闭系统(1)[root@localhost ~]# shutdown -h now # 关闭系统(2)[root@localhost ~]# init 0 # 关闭系统(3)[root@localhost ~]# telinit 0 # 按预定时间关闭系统[root@localhost...

    2019-12-07 服务器教程
  • linux重启命令 reboot与shutdown -r now的区别与联系

    在linux命令中reboot是重新启动,shutdown -r now是立即停止然后重新启动,都说他们两个是一样的,其实是有一定的区别的。shutdown命令可以安全地关闭或重启Linux系统,它在系统关闭之前给系统上的所有登录用户提示一条警告...

    2019-12-07 服务器教程
  • CentOS 7 如何使用命令重启或关机

    安装GNOME的朋友们首先切换到字符界面。切换到字符界面的方法如下: 先登陆进入系统,进入图形化界面,然后按Ctrl+Alt+F6(笔记本的是Ctrl+Alt+shift+Fn),进入字符界面。关机命令:shutdown或poweroffshutdown:shutdown -h now...

    2019-12-07 服务器教程
  • CentOS 7 正确关机重启的命令方法

    linux主要用于服务器领域,而在服务器上执行一项服务是永无止境的,除非遇到特殊情况,否则不会关机。和Windows不同,在linux系统下,很多进程是在后台执行的。在屏幕背后,可能有很多人同时在工作。如果直接按下电源的按钮,其他...

    2019-12-07 服务器教程
  • CentOS下的yum upgrade和yum update区别,没事别乱用!

    说明:生产环境对软件版本和内核版本要求非常精确,别没事有事随便的进行yum update操作!!!!!!!!!yum update: 升级所有包同时也升级软件和系统内核yum upgrade:只升级所有包,不升级软件和系统内核...

    2019-12-07 服务器教程
你可能感兴趣
热门浏览