ZipArchive::getStream
(PHP 5 >= 5.2.0, PHP 7, PECL zip >= 1.1.0)
ZipArchive::getStream - 获取文件处理程序到由其名称定义的条目(只读)。
描述
resource ZipArchive::getStream ( string $name )
获取文件处理程序到由其名称定义的条目。目前它只支持读取操作。
参数
name
要使用的条目的名称。
返回值
成功返回文件指针(资源)或失败时返回FALSE
的。
示例
Example #1 Get the entry contents with fread() and store it
<?php
$contents?=?'';
$z?=?new?ZipArchive();
if?($z->open('test.zip'))?{
????$fp?=?$z->getStream('test');
????if(!$fp)?exit("failed\n");
????while?(!feof($fp))?{
????????$contents?.=?fread($fp,?2);
????}
????fclose($fp);
????file_put_contents('t',$contents);
????echo?"done.\n";
}
?>
Example #2 Same as the previous example but with fopen() and the zip stream wrapper
<?php
$contents?=?'';
$fp?=?fopen('zip://'?.?dirname(__FILE__)?.?'/test.zip#test',?'r');
if?(!$fp)?{
????exit("cannot?open\n");
}
while?(!feof($fp))?{
????$contents?.=?fread($fp,?2);
}
echo?"$contents\n";
fclose($fp);
echo?"done.\n";
?>
Example #3 Stream wrapper and image, can be used with the xml function as well
<?php
$im?=?imagecreatefromgif('zip://'?.?dirname(__FILE__)?.?'/test_im.zip#pear_item.gif');
imagepng($im,?'a.png');
?>
← ZipArchive::getStatusString
ZipArchive::locateName →
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com