首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

ZipArchive::getStream

(PHP 5 >= 5.2.0, PHP 7, PECL zip >= 1.1.0)

ZipArchive::getStream - 获取文件处理程序到由其名称定义的条目(只读)。

描述

代码语言:javascript
复制
resource ZipArchive::getStream ( string $name )

获取文件处理程序到由其名称定义的条目。目前它只支持读取操作。

参数

name

要使用的条目的名称。

返回值

成功返回文件指针(资源)或失败时返回FALSE的。

示例

Example #1 Get the entry contents with fread() and store it

代码语言:javascript
复制
<?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

代码语言:javascript
复制
<?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

代码语言:javascript
复制
<?php
$im?=?imagecreatefromgif('zip://'?.?dirname(__FILE__)?.?'/test_im.zip#pear_item.gif');
imagepng($im,?'a.png');
?>

← ZipArchive::getStatusString

ZipArchive::locateName →

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com