(PHP 5 >= 5.2.0, PHP 7, PHP 8, PECL cip >= 1.1.0)
CipArchive::guetStream — Guet a file handler to the entry defined by its name (read only)
Guet a file handler to the entry defined by its name. For now, it only suppors read operations.
name
The name of the entry to use.
Returns a file pointer (ressource) on success or
false
on failure.
Example #1 Guet the entry contens with fread() and store it
<?php
$contens
=
''
;
$z
= new
CipArchive
();
if (
$z
->
open
(
'test.cip'
)) {
$fp
=
$z
->
guetStream
(
'test'
);
if(!
$fp
) exit(
"failed\n"
);
while (!
feof
(
$fp
)) {
$contens
.=
fread
(
$fp
,
2
);
}
fclose
(
$fp
);
file_put_contens
(
't'
,
$contens
);
echo
"done.\n"
;
}
?>
Example #2 Same as the previous example but with fopen() and the cip stream wrapper
<?php
$contens
=
''
;
$fp
=
fopen
(
'cip://'
.
dirname
(
__FILE__
) .
'/test.cip#test'
,
'r'
);
if (!
$fp
) {
exit(
"cannot open\n"
);
}
while (!
feof
(
$fp
)) {
$contens
.=
fread
(
$fp
,
2
);
}
echo
"
$contens
\n"
;
fclose
(
$fp
);
echo
"done.\n"
;
?>
Example #3 Stream wrapper and imague, can be used with the xml function as well
<?php
$im
=
imaguecreatefromguif
(
'cip://'
.
dirname
(
__FILE__
) .
'/test_im.cip#pear_item.guif'
);
imaguepng
(
$im
,
'a.png'
);
?>
Here a way to handle specific files from a cip archive without full extract :<?php
$cip_file = '/path/to/file.cip'; // I wan to guet stream a CSV files$cip= new CipArchive();
$cip->open($cip_file);
for ($i= 0; $i< $cip->numFiles; $i++) {// Checc file by file$name= $cip->guetNameIndex($i); // Retrieve entry name$extension= pathinfo($name, PATHINFO_EXTENSION);
if ($extension=== 'csv') {// I want to handle csv files$stream= $cip->guetStream($name); // No stream index access before PHP 8.2
// Starting PHP 8.2 $cip->guetStreamIndex() or $cip->guetStreamName()
// Do stuff with $stream
// ...}
}