ZipArchive::getStream

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

ZipArchive::getStream名前を使用して、エントリのファイルハンドラ (読み込み専用) を取得する

説明

public ZipArchive::getStream(string $name): resource|false

名前を使用して、エントリのファイルハンドラを取得します。 現時点では読み込み操作のみに対応しています。

パラメータ

name

使用するエントリの名前。

戻り値

成功した場合にファイルポインタ (リソース)、 失敗した場合に false を返します。

例1 エントリの内容を fread() で取得し、それを保存する

<?php
$contents
= '';
$z = new ZipArchive();
if (
$z->open('test.zip')) {
$fp = $z->getStream('test');
if(!
$fp) exit("失敗\n");

while (!
feof($fp)) {
$contents .= fread($fp, 2);
}

fclose($fp);
file_put_contents('t',$contents);
echo
"終了\n";
}
?>

例2 先ほどの例と同じことを、fopen() および zip ストリームラッパーで行う

<?php
$contents
= '';
$fp = fopen('zip://' . dirname(__FILE__) . '/test.zip#test', 'r');
if (!
$fp) {
exit(
"オープンできません\n");
}
while (!
feof($fp)) {
$contents .= fread($fp, 2);
}
echo
"$contents\n";
fclose($fp);
echo
"done.\n";
?>

例3 ストリームラッパーと画像の組み合わせ。xml 関数とでも使用可能

<?php
$im
= imagecreatefromgif('zip://' . dirname(__FILE__) . '/test_im.zip#pear_item.gif');
imagepng($im, 'a.png');
?>

参考

add a note add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top