downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

Our source is open

The syntax highlighted source is automatically generated by PHP from the plaintext script. If you're interested in what's behind the several functions we used, you can always take a look at the source of the following files:

Of course, if you want to see the source of this page, we have it available. You can also browse the SVN repository for this website on svn.php.net.

Source of: /manual/en/wrappers.php.php

<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$PARENTS = array();
include_once
dirname(__FILE__) ."/toc/wrappers.inc";
$setup = array (
 
'home' =>
  array (
   
0 => 'index.php',
   
1 => 'PHP Manual',
  ),
 
'head' =>
  array (
   
0 => 'UTF-8',
   
1 => 'en',
  ),
 
'this' =>
  array (
   
0 => 'wrappers.php.php',
   
1 => 'PHP input/output streams',
  ),
 
'up' =>
  array (
   
0 => 'wrappers.php',
   
1 => 'List of Supported Protocols/Wrappers',
  ),
 
'prev' =>
  array (
   
0 => 'wrappers.ftp.php',
   
1 => 'FTP and FTPS',
  ),
 
'next' =>
  array (
   
0 => 'wrappers.compression.php',
   
1 => 'Compression Streams',
  ),
);
$setup["toc"] = $TOC;
$setup["parents"] = $PARENTS;
manual_setup($setup);

manual_header();
?>
<div id="wrappers.php" class="section">
  <h2 class="title">PHP input/output streams</h2>

  <ul class="itemizedlist">
   <li class="listitem"><span class="simpara"><var class="filename">php://stdin</var></span></li>
   <li class="listitem"><span class="simpara"><var class="filename">php://stdout</var></span></li>
   <li class="listitem"><span class="simpara"><var class="filename">php://stderr</var></span></li>
   <li class="listitem"><span class="simpara"><var class="filename">php://output</var></span></li>
   <li class="listitem"><span class="simpara"><var class="filename">php://input</var></span></li>
   <li class="listitem"><span class="simpara"><var class="filename">php://filter</var> (available since PHP 5.0.0)</span></li>
   <li class="listitem"><span class="simpara"><var class="filename">php://memory</var> (available since PHP 5.1.0)</span></li>
   <li class="listitem"><span class="simpara"><var class="filename">php://temp</var> (available since PHP 5.1.0)</span></li>
  </ul>

  <p class="simpara">
   <var class="filename">php://stdin</var>, <var class="filename">php://stdout</var>
   and <var class="filename">php://stderr</var> allow direct access to
   the corresponding input or output stream of the PHP process.  The stream
   references a duplicate file descriptor, so if you open
   <var class="filename">php://stdin</var> and later close it, you close only your
   copy of the descriptor--the actual stream referenced by
   <b><tt class="constant">STDIN</tt></b> is unaffected.  Note that PHP exhibited buggy
   behavior in this regard until PHP 5.2.1.  It is recommended that you simply
   use the constants <b><tt class="constant">STDIN</tt></b>, <b><tt class="constant">STDOUT</tt></b>
   and <b><tt class="constant">STDERR</tt></b> instead of manually opening streams using
   these wrappers.
  </p>
  <p class="simpara">
   <var class="filename">php://output</var> allows you to write to the
   output buffer mechanism in the same way as
   <a href="function.print.php" class="function">print()</a> and <a href="function.echo.php" class="function">echo()</a>.
  </p>
  <p class="simpara">
   <var class="filename">php://input</var> allows you to read raw POST data.
   It is a less memory intensive alternative to
   <var class="varname"><a href="reserved.variables.httprawpostdata.php" class="classname">$HTTP_RAW_POST_DATA</a></var> and does not need any
   special <var class="filename">php.ini</var> directives.
   <var class="filename">php://input</var> is not available with
   <i>enctype=&quot;multipart/form-data&quot;</i>.
  </p>
  <p class="simpara">
   <var class="filename">php://stdin</var> and
   <var class="filename">php://input</var> are read-only, whereas
   <var class="filename">php://stdout</var>,
   <var class="filename">php://stderr</var> and
   <var class="filename">php://output</var> are write-only.
  </p>

  <p class="simpara">
   <var class="filename">php://filter</var> is a kind of meta-wrapper designed
   to permit the application of filters to a stream at the time of
   opening.  This is useful with all-in-one file functions such as
   <a href="function.readfile.php" class="function">readfile()</a>, <a href="function.file.php" class="function">file()</a>, and
   <a href="function.file-get-contents.php" class="function">file_get_contents()</a> where there is otherwise
   no opportunity to apply a filter to the stream prior the contents
   being read.
  </p>
  <p class="simpara">
   The <var class="filename">php://filter</var> target takes the following
   &#039;parameters&#039; as parts of its &#039;path&#039;.
  </p>
  <ul class="itemizedlist">
   <li class="listitem">
    <p class="para">
     <i>/resource=&lt;stream to be filtered&gt;</i>
     (<em class="emphasis">required</em>)  This parameter must be located at
     the end of your <var class="filename">php://filter</var> specification and
     should point to the stream which you want filtered.
     </p><div class="informalexample">
      <div class="example-contents programlisting">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">/*&nbsp;This&nbsp;is&nbsp;equivalent&nbsp;to&nbsp;simply:<br />&nbsp;&nbsp;&nbsp;readfile("http://www.example.com");<br />&nbsp;&nbsp;&nbsp;since&nbsp;no&nbsp;filters&nbsp;are&nbsp;actually&nbsp;specified&nbsp;*/<br /><br /></span><span style="color: #0000BB">readfile</span><span style="color: #007700">(</span><span style="color: #DD0000">"php://filter/resource=http://www.example.com"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
      </div>

     </div><p>
    </p>
   </li>
   <li class="listitem">
    <p class="para">
     <i>/read=&lt;filter list to apply to read chain&gt;</i>
     (<em class="emphasis">optional</em>)  This parameter takes one or more
     filternames separated by the pipe character <i>|</i>.
     </p><div class="informalexample">
      <div class="example-contents programlisting">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">/*&nbsp;This&nbsp;will&nbsp;output&nbsp;the&nbsp;contents&nbsp;of<br />&nbsp;&nbsp;&nbsp;www.example.com&nbsp;entirely&nbsp;in&nbsp;uppercase&nbsp;*/<br /></span><span style="color: #0000BB">readfile</span><span style="color: #007700">(</span><span style="color: #DD0000">"php://filter/read=string.toupper/resource=http://www.example.com"</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;This&nbsp;will&nbsp;do&nbsp;the&nbsp;same&nbsp;as&nbsp;above<br />&nbsp;&nbsp;&nbsp;but&nbsp;will&nbsp;also&nbsp;ROT13&nbsp;encode&nbsp;it&nbsp;*/<br /></span><span style="color: #0000BB">readfile</span><span style="color: #007700">(</span><span style="color: #DD0000">"php://filter/read=string.toupper|string.rot13/resource=http://www.example.com"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
      </div>

     </div><p>
    </p>
   </li>
   <li class="listitem">
    <p class="para">
     <i>/write=&lt;filter list to apply to write chain&gt;</i>
     (<em class="emphasis">optional</em>)  This parameter takes one or more
     filternames separated by the pipe character <i>|</i>.
     </p><div class="informalexample">
      <div class="example-contents programlisting">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">/*&nbsp;This&nbsp;will&nbsp;filter&nbsp;the&nbsp;string&nbsp;"Hello&nbsp;World"<br />&nbsp;&nbsp;&nbsp;through&nbsp;the&nbsp;rot13&nbsp;filter,&nbsp;then&nbsp;write&nbsp;to<br />&nbsp;&nbsp;&nbsp;example.txt&nbsp;in&nbsp;the&nbsp;current&nbsp;directory&nbsp;*/<br /></span><span style="color: #0000BB">file_put_contents</span><span style="color: #007700">(</span><span style="color: #DD0000">"php://filter/write=string.rot13/resource=example.txt"</span><span style="color: #007700">,</span><span style="color: #DD0000">"Hello&nbsp;World"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
      </div>

     </div><p>
    </p>
   </li>
   <li class="listitem">
    <span class="simpara">
     <i>/&lt;filter list to apply to both chains&gt;</i>
     (<em class="emphasis">optional</em>)  Any filter lists which are not
     prefixed specifically by <i>read=</i> or
     <i>write=</i> will be applied to both the read and
     write chains (as appropriate).
    </span>
   </li>
  </ul>

  <p class="simpara">
   The <var class="filename">php://memory</var> wrapper stores the data in the
   memory. <var class="filename">php://temp</var> behaves similarly, but uses a
   temporary file for storing the data when a certain memory limit is reached
   (the default is 2 MB).
  </p>
  <p class="simpara">
   The <var class="filename">php://temp</var> wrapper takes the following
   &#039;parameters&#039; as parts of its &#039;path&#039;:
  </p>
  <ul class="itemizedlist">
   <li class="listitem">
    <p class="para">
     <i>/maxmemory:&lt;number of bytes&gt;</i>
     (<em class="emphasis">optional</em>). This parameter allows changing the
     default value for the memory limit (when the data is moved to a temporary
     file).
     </p><div class="informalexample">
      <div class="example-contents programlisting">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$fiveMBs&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">5&nbsp;</span><span style="color: #007700">*&nbsp;</span><span style="color: #0000BB">1024&nbsp;</span><span style="color: #007700">*&nbsp;</span><span style="color: #0000BB">1024</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$fp&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">fopen</span><span style="color: #007700">(</span><span style="color: #DD0000">"php://temp/maxmemory:</span><span style="color: #0000BB">$fiveMBs</span><span style="color: #DD0000">"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'r+'</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">fputs</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"hello\n"</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;read&nbsp;what&nbsp;we&nbsp;have&nbsp;written<br /></span><span style="color: #0000BB">rewind</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #0000BB">stream_get_contents</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
      </div>

     </div><p>
    </p>
   </li>
  </ul>

  <p class="para">
   </p><table class="doctable table">
    <caption><b>
     Wrapper Summary (For <i>php://filter</i>,
     refer to summary of wrapper being filtered.)
    </b></caption>
   
     <thead valign="middle">
      <tr valign="middle">
       <th>Attribute</th>
       <th>Supported</th>
      </tr>

     </thead>

     <tbody valign="middle" class="tbody">
      <tr valign="middle">
       <td align="left">Restricted by <a href="filesystem.configuration.php#ini.allow-url-fopen" class="link">allow_url_fopen</a></td>
       <td align="left">No</td>
      </tr>

      <tr valign="middle">
       <td align="left">Restricted by <a href="filesystem.configuration.php#ini.allow-url-include" class="link">allow_url_include</a></td>
       <td align="left">
        <i>php://input</i>,
        <i>php://stdin</i>,
        <i>php://memory</i> and
        <i>php://temp</i> only.
       </td>
      </tr>

      <tr valign="middle">
       <td align="left">Allows Reading</td>
       <td align="left">
        <i>php://stdin</i>,
        <i>php://input</i>,
        <i>php://memory</i> and
        <i>php://temp</i> only.
       </td>
      </tr>

      <tr valign="middle">
       <td align="left">Allows Writing</td>
       <td align="left">
        <i>php://stdout</i>,
        <i>php://stderr</i>,
        <i>php://output</i>,
        <i>php://memory</i> and
        <i>php://temp</i> only.
       </td>
      </tr>

      <tr valign="middle">
       <td align="left">Allows Appending</td>
       <td align="left">
        <i>php://stdout</i>,
        <i>php://stderr</i>,
        <i>php://output</i>,
        <i>php://memory</i> and
        <i>php://temp</i> only. (Equivalent to writing)
       </td>
      </tr>

      <tr valign="middle">
       <td align="left">Allows Simultaneous Reading and Writing</td>
       <td align="left">
        <i>php://memory</i> and
        <i>php://temp</i> only.
       </td>
      </tr>

      <tr valign="middle">
       <td align="left">Supports <a href="function.stat.php" class="function">stat()</a></td>
       <td align="left">
        <i>php://memory</i> and
        <i>php://temp</i> only.
       </td>
      </tr>

      <tr valign="middle">
       <td align="left">Supports <a href="function.unlink.php" class="function">unlink()</a></td>
       <td align="left">No</td>
      </tr>

      <tr valign="middle">
       <td align="left">Supports <a href="function.rename.php" class="function">rename()</a></td>
       <td align="left">No</td>
      </tr>

      <tr valign="middle">
       <td align="left">Supports <a href="function.mkdir.php" class="function">mkdir()</a></td>
       <td align="left">No</td>
      </tr>

      <tr valign="middle">
       <td align="left">Supports <a href="function.rmdir.php" class="function">rmdir()</a></td>
       <td align="left">No</td>
      </tr>

     </tbody>
   
   </table>
<p>
  </p>
 </div><?php manual_footer(); ?>
 
show source | credits | sitemap | contact | advertising | mirror sites