<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Get a file handler to the entry defined by its name (read only).</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="ziparchive.getstatusstring.html">ZipArchive::getStatusString</a></div> <div class="next" style="text-align: right; float: right;"><a href="ziparchive.locatename.html">ZipArchive::locateName</a></div> <div class="up"><a href="class.ziparchive.html">ZipArchive</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="ziparchive.getstream" class="refentry"> <div class="refnamediv"> <h1 class="refname">ZipArchive::getStream</h1> <p class="verinfo">(PHP 5 >= 5.2.0, PECL zip >= 1.1.0)</p><p class="refpurpose"><span class="refname">ZipArchive::getStream</span> — <span class="dc-title">Get a file handler to the entry defined by its name (read only).</span></p> </div> <div class="refsect1 description" id="refsect1-ziparchive.getstream-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">resource</span> <span class="methodname"><strong>ZipArchive::getStream</strong></span> ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$name</code></span> )</div> <p class="para rdfs-comment"> Get a file handler to the entry defined by its name. For now it only supports read operations. </p> </div> <div class="refsect1 parameters" id="refsect1-ziparchive.getstream-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><em><code class="parameter">name</code></em></span> <dd> <p class="para"> The name of the entry to use. </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-ziparchive.getstream-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> Returns a file pointer (resource) on success or <strong><code>FALSE</code></strong> on failure. </p> </div> <div class="refsect1 examples" id="refsect1-ziparchive.getstream-examples"> <h3 class="title">Examples</h3> <div class="example" id="example-797"> <p><strong>Example #1 Get the entry contents with <span class="function"><a href="function.fread.html" class="function">fread()</a></span> and store it</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br />$content </span><span style="color: #007700">= </span><span style="color: #DD0000">''</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$z </span><span style="color: #007700">= new </span><span style="color: #0000BB">ZipArchive</span><span style="color: #007700">();<br />if (</span><span style="color: #0000BB">$z</span><span style="color: #007700">-></span><span style="color: #0000BB">open</span><span style="color: #007700">(</span><span style="color: #DD0000">'test.zip'</span><span style="color: #007700">)) {<br /> </span><span style="color: #0000BB">$fp </span><span style="color: #007700">= </span><span style="color: #0000BB">$z</span><span style="color: #007700">-></span><span style="color: #0000BB">getStream</span><span style="color: #007700">(</span><span style="color: #DD0000">'test'</span><span style="color: #007700">);<br /> if(!</span><span style="color: #0000BB">$fp</span><span style="color: #007700">) exit(</span><span style="color: #DD0000">"failed\n"</span><span style="color: #007700">);<br /><br /> while (!</span><span style="color: #0000BB">feof</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">)) {<br /> </span><span style="color: #0000BB">$contents </span><span style="color: #007700">.= </span><span style="color: #0000BB">fread</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">, </span><span style="color: #0000BB">2</span><span style="color: #007700">);<br /> }<br /><br /> </span><span style="color: #0000BB">fclose</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">);<br /> </span><span style="color: #0000BB">file_put_contents</span><span style="color: #007700">(</span><span style="color: #DD0000">'t'</span><span style="color: #007700">,</span><span style="color: #0000BB">$contents</span><span style="color: #007700">);<br /> echo </span><span style="color: #DD0000">"done.\n"</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> </div> <div class="example" id="example-798"> <p><strong>Example #2 Same as the previous example but with <span class="function"><a href="function.fopen.html" class="function">fopen()</a></span> and the zip stream wrapper</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br />$fp </span><span style="color: #007700">= </span><span style="color: #0000BB">fopen</span><span style="color: #007700">(</span><span style="color: #DD0000">'zip://' </span><span style="color: #007700">. </span><span style="color: #0000BB">dirname</span><span style="color: #007700">(</span><span style="color: #0000BB">__FILE__</span><span style="color: #007700">) . </span><span style="color: #DD0000">'/test.zip#test'</span><span style="color: #007700">, </span><span style="color: #DD0000">'r'</span><span style="color: #007700">);<br />if (!</span><span style="color: #0000BB">$fp</span><span style="color: #007700">) {<br /> exit(</span><span style="color: #DD0000">"cannot open\n"</span><span style="color: #007700">);<br />}<br />while (!</span><span style="color: #0000BB">feof</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">)) {<br /> </span><span style="color: #0000BB">$contents </span><span style="color: #007700">.= </span><span style="color: #0000BB">fread</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">, </span><span style="color: #0000BB">2</span><span style="color: #007700">);<br />}<br />echo </span><span style="color: #DD0000">"</span><span style="color: #0000BB">$contents</span><span style="color: #DD0000">\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">fclose</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">);<br />echo </span><span style="color: #DD0000">"done.\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> </div> <div class="example" id="example-799"> <p><strong>Example #3 Stream wrapper and image, can be used with the xml function as well</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br />$im </span><span style="color: #007700">= </span><span style="color: #0000BB">imagecreatefromgif</span><span style="color: #007700">(</span><span style="color: #DD0000">'zip://' </span><span style="color: #007700">. </span><span style="color: #0000BB">dirname</span><span style="color: #007700">(</span><span style="color: #0000BB">__FILE__</span><span style="color: #007700">) . </span><span style="color: #DD0000">'/test_im.zip#pear_item.gif'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">imagepng</span><span style="color: #007700">(</span><span style="color: #0000BB">$im</span><span style="color: #007700">, </span><span style="color: #DD0000">'a.png'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> </div> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="ziparchive.getstatusstring.html">ZipArchive::getStatusString</a></div> <div class="next" style="text-align: right; float: right;"><a href="ziparchive.locatename.html">ZipArchive::locateName</a></div> <div class="up"><a href="class.ziparchive.html">ZipArchive</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>