文字

zlib://

bzip2://

zip://

zlib:// -- bzip2:// -- zip://压缩流

说明

zlib: PHP 4.0.4 - PHP 4.2.3(仅支持带 fopencookie 的系统)

compress.zlib://compress.bzip2:// PHP 4.3.0 及以上

zlib: 的功能类似 gzopen() ,但是 其数据流还能被 fread() 和其他文件系统函数使用。 自 PHP 4.3.0 后这个不建议被使用,因为会和其他带“:”字符的文件名混淆; 请使用 compress.zlib:// 作为替代。

compress.zlib://compress.bzip2:// gzopen() bzopen() 是相等的。并且可以在不支持 fopencookie 的系统中使用。

ZIP 扩展 注册了 zip: 封装协议。

可选项

  • compress.zlib://file.gz
  • compress.bzip2://file.bz2
  • zip://archive.zip#dir/file.txt

用法

封装协议摘要
属性 支持
受限于 allow_url_fopen No
允许读取 Yes
允许写入 Yes(除了 zip://
允许附加 Yes(除了 zip://
允许同时读写 No
支持 stat() No,请使用普通的 file:// 封装器统计压缩文件。
支持 unlink() No,请使用 file:// 封装器删除压缩文件。
支持 rename() No
支持 mkdir() No
支持 rmdir() No

用户评论:

[#1] eragonjml at googlemail dot com [2013-09-19 17:00:59]

@alvaro at demogracia dot com

well in fact that is wrong!
right code is:

<?php 

$fp 
fopen('compress.zip://./foo.zip#bar.txt''r'); 
if( 
$fp ){ 
    while( !
feof($fp) ){ 
        echo 
fread($fp8192); 
    } 
    
fclose($fp); 


?>
 

as you might see you just have to add a "compress."

maybe when you posted this note is was right (2 years ago) but today its wrong... :/

sry for my english i am german :)

[#2] alvaro at demogracia dot com [2011-04-12 07:41:33]

Example on how to read an entry from a ZIP archive (file "bar.txt" inside "./foo.zip"):

<?php

$fp 
fopen('zip://./foo.zip#bar.txt''r');
if( 
$fp ){
    while( !
feof($fp) ){
        echo 
fread($fp8192);
    }
    
fclose($fp);
}

?>


Also, apparently, the "zip:" wrapper does not allow writing as of PHP/5.3.6. You can read http://php.net/ziparchive-getstream for further reference since the underlying code is probably the same.

[#3] joshualross at gmail dot com [2007-08-19 12:24:17]

I had a difficult time finding how to use compress.zlib with an http resource so I thought I would post what I found
<?php
$file 
'compress.zlib://http://www.example.com/myarchive.gz';
$fr fopen($file'rb');
?>


Per the bugreport I found here (http://bugs.php.net/bug.php?id=29045)

上一篇: 下一篇: